Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int g[110][100];
- int c[110];
- int n, m, f;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int a, b;
- cin >> n >> m;
- f = 0;
- if(n==0||m==0)
- {
- cout << "YES";
- return 0;
- }
- for(int i = 0; i < m; i++)
- {
- cin >> a >> b;
- a--;
- b--;
- g[a][b]+=1;
- g[b][a]+=1;
- }
- for(int i = 0; i < n; i++)
- {
- c[i]=-1;
- g[i][i]=0;
- }
- for(int i = 0; i < n; i++)
- {
- if (c[i]==-1)
- {
- queue <int> q;
- q.push(i);
- c[i]=2;
- int v;
- while(!q.empty())
- {
- v = q.front();
- q.pop();
- for(int ii = 0 ; ii < n; ii++)
- {
- if(g[v][ii]!=0)
- {
- if(c[ii]==-1)
- {
- c[ii]=3-c[v];
- q.push(ii);
- }
- else if (c[ii]==c[v])
- {
- cout << "NO ";
- return 0;
- }
- }
- }
- }
- }
- }
- cout << "YES" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement