//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 500
#define MOD 1000000007
int n,m,a[MAX],mk[MAX],col[MAX],flag;
vi v[MAX];
int dfs(int x,int c){
int i;
mk[x]=1;
col[x]=c;
f(i,0,v[x].size()){
if(!mk[v[x][i]])
dfs(v[x][i],1-c);
else{
if(col[v[x][i]]==c)
flag=1;
}
}
}
int main(){
int tt=1,r,k,i,p,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;
while(cin>>n){
if(n==0)
break;
z=-1;
flag=0;
clr(mk,0);
while(cin>>x>>y){
if(x==0 && y==0)
break;
v[x].pb(y);
v[y].pb(x);
z=max(z,max(x,y));
}
dfs(z,0);
if(flag)
printf("NO\n");
else
printf("YES\n");
f(i,0,z+5)
v[i].clear();
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 500
#define MOD 1000000007
int n,m,a[MAX],mk[MAX],col[MAX],flag;
vi v[MAX];
int dfs(int x,int c){
int i;
mk[x]=1;
col[x]=c;
f(i,0,v[x].size()){
if(!mk[v[x][i]])
dfs(v[x][i],1-c);
else{
if(col[v[x][i]]==c)
flag=1;
}
}
}
int main(){
int tt=1,r,k,i,p,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;
while(cin>>n){
if(n==0)
break;
z=-1;
flag=0;
clr(mk,0);
while(cin>>x>>y){
if(x==0 && y==0)
break;
v[x].pb(y);
v[y].pb(x);
z=max(z,max(x,y));
}
dfs(z,0);
if(flag)
printf("NO\n");
else
printf("YES\n");
f(i,0,z+5)
v[i].clear();
}
return 0;
}
No comments:
Post a Comment