Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <bits/stdc++.h>
- //%lld
- typedef long long ll;
- #define si(a) scanf("%d", &a)
- #define sii(a, b) scanf("%d%d", &a, &b)
- using namespace std;
- int main(){
- //freopen("in.txt", "r", stdin);
- //freopen("out.txt", "w", stdout);
- vector<int>grafo[1000];
- queue<int> fila;
- int cor[1000];
- int v, a, b, aux;
- bool c = true;
- while(cin>>v){
- if(v==0)break;
- else{
- c = true;
- for(int i = 0;i<v;i++){
- sii(a, b);
- grafo[a].push_back(b);
- grafo[b].push_back(a);
- }
- fila.push(0);
- cor[0] = 1;
- while(!fila.empty()&&c){
- aux = fila.front();
- fila.pop();
- for(int i = 0;i<grafo[aux].size();i++){
- if(cor[grafo[aux][i]]==0){//nao ta pintado
- if(cor[aux]==1)cor[grafo[aux][i]] = 2;
- else cor[grafo[aux][i]] = 1;
- fila.push(grafo[aux][i]);
- }else{//ta pintado ja
- if((cor[aux]==cor[grafo[aux][i]])||(cor[aux]==cor[grafo[aux][i]])){
- c = false;
- break;
- }
- }
- }
- }
- if(c)puts("BICOLORABLE.");
- else puts("NOT BICOLORABLE.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment