Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define pf printf
- #define sf scanf
- #define none 0
- #define white 1
- #define black 2
- #define DBG cout << "DEBUG " << endl;
- using namespace std;
- long n,m,edges;
- vector < int > adjList[1234];
- bitset < 1234 > visited;
- int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
- int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
- int color[12345];
- bool pass = true;
- void dfs( int p, int c, int clr ){
- if(color[p] == clr && visited[p]) {
- pass = false;
- return;
- }
- color[p] = clr;
- for( auto x : adjList[p] ){
- if( x != c && !visited[x] ){
- visited[x] = 1;
- dfs( x, p ,clr^1);
- }
- }
- }
- void print(){
- for( int i=1; i<=edges; i++ ){
- int sz = adjList[i].size();
- cout << i << " -> " ;
- for( int j=0; j<sz; j++ ){
- cout << adjList[i][j] << " ";
- }
- cout << endl;
- }
- }
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt","rt",stdin);
- // freopen("out.txt","wt",stdout);
- #endif
- memset( color , -1 , sizeof color );
- cin >> edges;
- for( int i=1; i<=edges; i++ ){
- int x,y;
- cin >> x >> y;
- adjList[x].push_back( y );
- adjList[y].push_back( x );
- }
- dfs( 1, -1, 0);
- puts("");
- for( int i=1; i<=7; i++ ) cout << i << " " << color[i] << endl;
- puts("");
- if(pass)
- cout << "The Graph is BI-COLORABLE" << endl;
- else
- cout << "The Graph is not BI-COLORABLE" << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment