Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector< vector<int> > g;
- //c=0 is one color, c=1 is another color
- bool color(vector< vector<int> >&g, vector<int>& gc, int u, int c){
- if(gc[u]==NULL){
- gc[u]=c;
- for(int v : g[u]){
- if(!color(g,gc,v,1-c)) return false;
- }
- return true;
- }
- else return gc[u]==c;
- }
- bool complete_coloring(vector< vector<int> >&g, vector<int>& gc, int x){
- if(x == gc.size()-1) return true;
- else{
- if(gc[x]==NULL){
- return color(g,gc,x,0) && complete_coloring(g,gc,x+1);
- }
- else return complete_coloring(g,gc,x+1);
- }
- }
- int main(){
- int n,m;
- while(cin>>n){
- cin>>m;
- g = vector< vector<int> > (n);
- int x,y;
- for(int i=0; i<m; ++i){
- cin>>x>>y;
- g[x].push_back(y);
- g[y].push_back(x);
- }
- vector<int> gc(n);
- if(complete_coloring(g,gc,0)) cout<<"yes"<<endl;
- else cout<<"no"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement