一道DFS题..
不说了,说多了全是泪..
// File Name: 11396.cpp // Author: Zlbing // Created Time: 2013/3/29 12:13:47 #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #include<stack> #include<cmath> #include<queue> using namespace std; #define CL(x,v); memset(x,v,sizeof(x)); #define INF 0x3f3f3f3f #define LL long long #define REP(i,r,n) for(int i=r;i<=n;i++) #define RREP(i,n,r) for(int i=n;i>=r;i--) const int MAXN=305; vector<int> G[MAXN]; int vis[MAXN]; int n; bool dfs(int u,int flag) { if(vis[u]>=0) { if(vis[u]==flag) return true; else return false; } vis[u]=flag; if(dfs(G[u][0],flag^1)&&dfs(G[u][1],flag^1)&&dfs(G[u][2],flag^1)) return true; else return false; } int main() { while(~scanf("%d",&n)) { if(n==0)break; REP(i,1,n)G[i].clear(); int a,b; while(true) { scanf("%d%d",&a,&b); if(a==0&&b==0)break; G[a].push_back(b); G[b].push_back(a); } if(n&1) { puts("NO"); continue; } CL(vis,-1); if(dfs(1,1)) puts("YES"); else puts("NO"); } return 0; }