• the meaning of problems
N given individual, m games;
This m race, the two battle in every game, part of a "good player" belonging to another "bad player";
Give you x number of already established "good player" and the y have been identified "bad player".
Q. Can I n these individuals into two categories, one of which belongs to the "good player", and the other belongs to the "bad player";
That there is no person that is part of "good player" and belonging to the "bad player";
If so, output "YES", on the contrary, the output "NO";
•answer
For every game of the two $ u, v $, even a two-way side $ u \ rightarrow v \, \ v \ rightarrow u $;
Then DFS staining.
Start with the already identified $ x + y $ of them began, staining associated with people, contradictions output "NO";
Then for people uncertain, enumerated dyeing, contradictions output "NO";
If there is no contradiction, output "YES";
•Code
View Code1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e3+50; 4 const int M=1e4+50; 5 6 int n,m,x,y; 7 int num; 8 int head[N]; 9 struct Edge 10 { 11 int to; 12 int next; 13 }G[M<<1]; 14 void addEdge(int u,int v) 15 { 16 G[num]={v,head[u]}; 17 head[u]=num++; 18 } 19 int col[N];///0:Good , 1:bad 20 int g[N]; 21 int b[N]; 22 bool ok; 23 24 void DFS(int u,int flag) 25 { 26 col[u]=flag; 27 for(int i=head[u];~i && !ok;i=G[i].next) 28 { 29 int= V G [I] .to; 30 31 is IF (COL [V] == - . 1 ) 32 the DFS (V, ^ In Flag . 1 ); 33 is 34 is IF (COL [V] == COL [U]) /// u, v opposition, if col [u] = col [v ] appear contradictory 35 OK = to true ; 36 } 37 [ } 38 is char * the Solve () 39 { 40 for ( int I = . 1 ; I <= X; ++ I) 41 is { 42 is int U = G [I]; 43 is OK =false; 44 if(col[u] == -1) 45 DFS(u,0); 46 if(ok || col[u] == 1) 47 return "NO"; 48 } 49 for(int i=1;i <= y;++i) 50 { 51 int u=b[i]; 52 if(col[u] == -1) 53 DFS(u,1); 54 55 if(ok || col[u] == 0) 56 return "NO"; 57 } 58 for(int i=1;i <= n;++i) 59 { 60 ok=false; 61 if(col[i] == -1 && head[i] != -1) 62 DFS(i,0); 63 64 if(ok) 65 return "NO"; 66 } 67 return "YES"; 68 } 69 void Init() 70 { 71 num=0; 72 for(int i=0;i <= n;++i) 73 { 74 col[i]=-1; 75 head[i]=-1; 76 } 77 } 78 int main() 79 { 80 // freopen("C:\\Users\\hyacinthLJP\\Desktop\\C++WorkSpace\\in&&out\\contest","r",stdin); 81 while(~scanf("%d%d%d%d",&n,&m,&x,&y)) 82 { 83 Init(); 84 for(int i=1;i <= m;++i) 85 { 86 int u,v; 87 scanf("%d%d",&u,&v); 88 addEdge(u,v); 89 addEdge(v,u); 90 } 91 for(int i=1;i <= x;++i) 92 scanf("%d",g+i); 93 for(int i=1;i <= y;++i) 94 scanf("%d",b+i); 95 puts(Solve()); 96 } 97 return 0; 98 }