北大OJ1308
来源:互联网 发布:sql限制返回条数 编辑:程序博客网 时间:2024/05/29 08:11
#include<iostream> #include <cstdio> #include<cstring> using namespace std; struct node { int u,v; }edge[1005]; int parent[1005]; int findset(int x) { if(parent[x]==-1) return x; parent[x]=findset(parent[x]); return parent[x]; } void Union(int x,int y) { parent[y]=x; } int main() { int a,b,i=0,flag,u,v,t,k=1; while(1) { flag=1;i=1; cin>>a>>b; if(a==-1&&b==-1) break; memset(parent,-1,sizeof(parent)); if(a==0&&b==0) { cout<<"Case "<<k++<<" is a tree."<<endl; continue; } edge[0].u=a; edge[0].v=b; while(cin>>a>>b&&a&&b) { edge[i].u=a; edge[i++].v=b; } for (t=0;t<i;t++) { u= findset(edge[t].u); v= findset(edge[t].v); if(u==v||v!=edge[t].v) /* 成环或者一个节点的入度大于 1 */ { flag=0; break; } else Union(u,v);//合并顶点 } if(flag) { u=findset(edge[0].u); for(t=1;t<i&&u==findset(edge[t].u);t++); if(t>=i) cout<<"Case "<<k<<" is a tree."<<endl; else cout<<"Case "<<k<<" is not a tree."<<endl; } else cout<<"Case "<<k<<" is not a tree."<<endl; k++; } return 0; }
0 0
- 北大OJ1308
- 北大简介
- 北大青鸟
- 北大青鸟
- 北大青鸟
- 北大acm1005
- 北大acm1008
- 北大1547
- 北大1120
- 北大1019
- 北大1006
- 北大1590
- 北大1491
- 北大1591
- 北大1595
- 北大2894
- 北大1001
- 北大1699
- java键盘输入
- strstr
- c语言输入输出优化
- DoTween - Sequence
- POJ 2586 贪心
- 北大OJ1308
- ndk for mac 下载地址
- 找出数组中的第K大的元素
- Android实现简单的文件下载
- 北大OJ3414
- iOS 9 请求网络数据出现:App Transport Security has blocked a cleartext HTTP (http://) resource load since it
- 从头认识java-12.5 代理以及动态代理
- xcode 使用代码块Code Snippets
- Struts2的国际化