Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main()
- {
- int a,b,x,y;
- cin>>b;
- cin>>a;
- vector<int>par[b];
- int boja[b];
- for(int i=0;i<a;i++)
- {
- cin>>x>>y;
- par[x].push_back(y);
- par[y].push_back(x);
- }
- for(int i=0;i<b;i++)
- {
- boja[i]=-1;
- }
- bool t=false;
- queue<int>Q;
- Q.push(0);
- boja[0]=0;
- while(!Q.empty())
- {
- int teme=Q.front();
- Q.pop();
- if(t==true)
- {
- cout<<"NO";
- return 0;
- }
- for(int i=0;i<par[teme].size();i++)
- {
- int sosed=par[teme][i];
- int boja_za_sleden_sosed = -1;
- if(boja[teme] == 0) {
- boja_za_sleden_sosed = 1;
- }
- else {
- boja_za_sleden_sosed = 0;
- }
- if(boja[sosed] == -1) {
- boja[sosed] = boja_za_sleden_sosed;
- Q.push(sosed);
- }
- else if(boja[sosed] == boja[teme]) {
- t = true;
- break;
- }
- }
- }
- if(t==false)
- {
- cout<<"YES" << endl;
- }
- else {
- cout << "NO" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement