标签:style blog http color io os ar java for
3 3 0 1 0 1 2 0
YES
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 110; 18 int g[maxn][maxn],color[maxn],n; 19 bool bfs(int v) { 20 queue<int>q; 21 color[v] = 0; 22 q.push(v); 23 while(!q.empty()) { 24 int u = q.front(); 25 q.pop(); 26 for(int i = 1; i <= n; ++i) { 27 if(i == u || g[u][i] == 2) continue; 28 if(color[i] == -1) { 29 color[i] = color[u]^1; 30 q.push(i); 31 } else if(color[i] == color[u]) return false; 32 } 33 } 34 return true; 35 } 36 int main() { 37 while(~scanf("%d",&n)) { 38 memset(g,0,sizeof(g)); 39 memset(color,-1,sizeof(color)); 40 for(int i = 1; i <= n; ++i) { 41 int j = 0; 42 while(scanf("%d",&j),j) { 43 g[i][j]++; 44 g[j][i]++; 45 } 46 } 47 bool flag = true; 48 for(int i = 1; i <= n; ++i) 49 if(color[i] == -1) { 50 flag = bfs(i); 51 if(!flag) break; 52 } 53 if(flag) puts("YES"); 54 else puts("NO"); 55 } 56 return 0; 57 }
标签:style blog http color io os ar java for
原文地址:http://www.cnblogs.com/crackpotisback/p/4041358.html