并查集都不用的吧。。。直接模拟就完了。
附代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#define MAXN 10010
using namespace std;
int n,m,f[MAXN];
bool flag=true;
char tp[100000],*p1=tp,*p2=tp;
char get_char(){
return p1==p2&&(p2=(p1=tp)+fread(tp,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
int date=0,w=1;char c=0;
while(c<'0'||c>'9'){if(c=='-')w=-1;c=get_char();}
while(c>='0'&&c<='9'){date=date*10+c-'0';c=get_char();}
return date*w;
}
void solve(){
n=read();m=read();
for(int i=1,x,y;i<=m&&flag;i++){
x=read();y=read();
if(x==y)continue;
if(f[x]!=y&&f[x])flag=false;
if(f[y]!=x&&f[y])flag=false;
f[x]=y;f[y]=x;
}
if(flag)printf("Nice\n");
else printf("Error\n");
}
int main(){
solve();
return 0;
}
京公网安备 11010502036488号