#include <bits/stdc++.h>
using namespace std;
vector<int>edges[1000];
queue<int>q;
int color[1000],visited[1000],tn;
int bipartite(int s)
{
int j,k,fr;
memset(color,-1,sizeof color);
color[s]=1;
while(!q.empty())
{
q.pop();
}
q.push(s);
for(j=1;j<=tn;j++)
{
visited[j]=0;
}
visited[s]=1;
while(!q.empty())
{
fr=q.front();
//cout<<"Size Of "<<fr<<"="<<edges[fr].size()<<endl;
for(k=0;k<edges[fr].size();k++)
{
if(visited[edges[fr][k]]==0 && color[edges[fr][k]]==-1)
{
q.push(edges[fr][k]);
visited[edges[fr][k]]=1;
color[edges[fr][k]]=1-color[fr];
}
}
for(k=0;k<edges[fr].size();k++)
{
if(visited[edges[fr][k]]==1 && color[edges[fr][k]]==color[fr])
{
return false;
}
}
q.pop();
}
return true;
}
int main()
{
int i,e,p,n,u,v,f,m,t,y;
//freopen("11396.txt","r",stdin);
//freopen("11396out.txt","w",stdout);
while(1)
{
cin>>tn;
e=(tn*3)/2;
if(tn==0)
{
break;
}
memset(edges,0,sizeof edges);
while(1)
{
cin>>u>>v;
if(u==0 && v==0)
{
break;
}
edges[u].push_back(v);
edges[v].push_back(u);
}
if(bipartite(1))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
0 comments:
Post a Comment