1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <vector>
 5 
 6 using namespace std;
 7 
 8 const int max_N = 1000+2;
 9 
10 // 图的邻接表
11 vector<int> G[max_N];
12 // 顶点数
13 int N;
14 int color[max_N];
15 
16 
17 bool dfs(int v,int c)
18 {
19     // 染色
20     color[v]=c;
21 
22     // 找遍所有相邻点,看有无重色相邻顶点
23     for(int i=0;i<G[v].size();++i)
24     {
25 
26         int to=G[v][i];
27         //printf("%d ",to);
28         if(color[to]==c)
29         {
30             return false;
31         }
32         else if(color[to]==0)
33         {
34             dfs(to,-c);
35         }
36     }
37     return true;
38 }
39 
40 
41 void solve()
42 {
43     memset(color,0,sizeof(color));
44 
45     for(int i=0;i<N;++i)
46     {
47         if(color[i]==0)
48         {
49             if(dfs(i,1)==false)
50             {
51                 printf("NO\n");
52                 return;
53             }
54         }
55     }
56 
57     printf("YES\n");
58 }
59 
60 
61 int main()
62 {
63     int x,y;
64     scanf("%d",&N);
65     while(scanf("%d %d",&x,&y)!=EOF)
66     {
67         if(x==0 && y==0)
68         {
69             break;
70         }
71         G[x].push_back(y);
72         G[y].push_back(x);
73     }
74 
75     solve();
76 
77     return 0;
78 }
79 
80 /*test
81 2
82 0 1
83 0 2
84 1 2
85 0 0
86 
87 4
88 0 1
89 0 3
90 1 2
91 2 3
92 0 0
93 
94 */

 

posted on 2020-02-14 22:26  带你AK,带你飞  阅读(131)  评论(0编辑  收藏  举报