wa了!!!
by 李湛然 @ 2019-12-29 11:53:23
因为老天靠你不顺眼!!!知道吗
by KokiNiwa @ 2019-12-29 12:03:53
@[李湛然](/user/195705)
by KokiNiwa @ 2019-12-29 12:04:05
你神经病!!!!!!!
by 李湛然 @ 2019-12-29 12:17:47
山前留名
by 7KByte @ 2019-12-29 13:17:32
~~**已举报**~~
by 小黄鸭GC @ 2020-03-07 12:40:38
~~举报成功~~
by Likejie_Hooray @ 2021-08-23 17:23:44
```
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 50005;
inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
int n,cnt,num[MAXN];
int a[MAXN][3];
int now[MAXN],ans=1e9;
bool vis[MAXN];
int main(){
n=rd();
for(register int i=1;i<=n;i++) a[i][1]=rd(),a[i][2]=rd();
for(register int i=1;i<=n;i++)
if((a[a[i][1]][1]!=i && a[a[i][1]][2]!=i )
||(a[a[i][2]][1]!=i && a[a[i][2]][2]!=i)){
puts("-1");
return 0;
}
int x=a[1][1];now[++cnt]=1;vis[1]=1;
while(x!=1){
if(vis[x]) break;
now[++cnt]=x;
vis[x]=1;
if(!vis[a[x][1]]) x=a[x][1];
else x=a[x][2];
}
for(register int i=1;i<=n;i++) num[(i-now[i]+n)%n]++;
for(register int i=0;i<n;i++) ans=min(ans,n-num[i]),num[i]=0;
cnt=0;now[++cnt]=1;memset(vis,false,sizeof(vis));x=a[1][2];vis[1]=1;
while(x!=1){
if(vis[x]) break;
now[++cnt]=x;
vis[x]=1;
if(!vis[a[x][1]]) x=a[x][1];
else x=a[x][2];
}
for(register int i=1;i<=n;i++) num[(i-now[i]+n)%n]++;
for(register int i=0;i<n;i++) ans=min(ans,n-num[i]);
printf("%d",ans);
return 0;
}
```
by todayfinish @ 2022-09-08 13:29:15
考古
by shengheng @ 2023-09-03 11:45:10