#include<cstdio>
#include<cstring>
using namespace std;
struct node{
int to,next;
}e[10000];
int head[10000],cnt,vis[100000];
void add_edge(int from,int to){
e[cnt].to=to;
e[cnt].next=head[from];
head[from]=cnt++;
}
int dfs(int u,int v,int flag){
vis[u]=flag;
for(int i=head[u];i!=-1;i=e[i].next){
int to=e[i].to;
if(to==v)
continue;
if(vis[to]!=-1){
if(vis[to]==flag)
return 0;
continue;
}
if(!dfs(to,u,flag^1))
return 0;
}
return 1;
}
int main(){
int a,b,n;
while(scanf("%d",&n) == 1 && n){
cnt=0;
memset(head,-1,sizeof(head));
memset(vis,-1,sizeof(vis));
while(scanf("%d%d",&a,&b) == 2 && (a+b)){
add_edge(a,b);
add_edge(b,a);
}
if(dfs(1,-1,1))
printf("YES\n");
else
printf("NO\n");
}
}
uva 11396 二分图判定 (每条边连接的点不在同一范围内)
最新推荐文章于 2022-03-14 14:57:35 发布