Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* UVa 11396 using bipartite graph check*/
- #include<cstdio>
- #include<queue>
- using namespace std;
- vector<int> AdjList[510];
- int main()
- {
- //freopen("in.txt","r",stdin);
- int n;
- while(scanf("%d",&n)&& n){
- for(int i=0;i<510;i++) AdjList[i].clear();
- int u,v;
- while(scanf("%d %d",&u,&v)&& (u!=0 || v!=0)){
- AdjList[u].push_back(v);
- AdjList[v].push_back(u);
- }
- queue<int> q;q.push(1);
- vector<int> color(n,500);color[1]=0;
- bool isBipartite=true;
- while(!q.empty()&isBipartite){
- int u=q.front();q.pop();
- int sz=AdjList[u].size();
- for(int j=0;j<sz;j++){
- int v=AdjList[u][j];
- if(color[v]==500){
- color[v]=1-color[u];
- q.push(v);
- }
- else if(color[v]==color[u]){
- isBipartite=false;break;
- }
- }
- }
- if(isBipartite) printf("YES\n");
- else printf("NO\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement