Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int g[110][100];
  6. int c[110];
  7. int n, m, f;
  8.  
  9.  
  10. int main()
  11. {
  12.  
  13. ios_base::sync_with_stdio(0);
  14. cin.tie(0);
  15. cout.tie(0);
  16.  
  17. freopen("input.txt", "r", stdin);
  18. freopen("output.txt", "w", stdout);
  19.  
  20. int a, b;
  21. cin >> n >> m;
  22. f = 0;
  23. if(n==0||m==0)
  24. {
  25. cout << "YES";
  26. return 0;
  27. }
  28. for(int i = 0; i < m; i++)
  29. {
  30. cin >> a >> b;
  31. a--;
  32. b--;
  33. g[a][b]+=1;
  34. g[b][a]+=1;
  35. }
  36. for(int i = 0; i < n; i++)
  37. {
  38. c[i]=-1;
  39. g[i][i]=0;
  40. }
  41. for(int i = 0; i < n; i++)
  42. {
  43. if (c[i]==-1)
  44. {
  45. queue <int> q;
  46. q.push(i);
  47. c[i]=2;
  48. int v;
  49. while(!q.empty())
  50. {
  51. v = q.front();
  52. q.pop();
  53. for(int ii = 0 ; ii < n; ii++)
  54. {
  55. if(g[v][ii]!=0)
  56. {
  57. if(c[ii]==-1)
  58. {
  59. c[ii]=3-c[v];
  60. q.push(ii);
  61. }
  62. else if (c[ii]==c[v])
  63. {
  64. cout << "NO ";
  65. return 0;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. cout << "YES" << endl;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement