UVA 10410(p180)----Tree Reconstruction
来源:互联网 发布:php授权查询系统源码 编辑:程序博客网 时间:2024/06/05 20:59
#include<bits/stdc++.h>#define debuusing namespace std;const int maxn=1010;int n,root,v;int d[maxn];stack<int> s;vector<int> g[maxn];int main(){#ifdef debug freopen("in.in","r",stdin);#endif // debug while(scanf("%d",&n)!=EOF) { memset(d,0,sizeof(d)); while(!s.empty()) s.pop(); for(int i=0; i<n; i++) { int x; scanf("%d",&x); g[x].clear(); d[x]=i; } scanf("%d",&root); s.push(root); for(int i=1; i<n; i++) { scanf("%d",&v); while(1) { int u=s.top(); if(u==root||d[v]>d[u]+1) { s.push(v); g[u].push_back(v); break; } else s.pop(); } } for(int i=1; i<=n; i++) { printf("%d:",i); for(int j=0; j<g[i].size(); j++) printf(" %d",g[i][j]); printf("\n"); } } return 0;}
0 0
- UVA 10410(p180)----Tree Reconstruction
- UVA - 10410 Tree Reconstruction
- Uva - 10410 - Tree Reconstruction
- uva 10410 - Tree Reconstruction
- uva 10410 - Tree Reconstruction
- Uva-10410 Tree Reconstruction
- UVA 10410 Tree Reconstruction
- uva 10410 - Tree Reconstruction(栈)
- UVA 10410 - Tree Reconstruction(树)
- UVa 10410 - Tree Reconstruction(树)
- UVA 10410——Tree Reconstruction
- Tree Reconstruction UVA
- 习题6-11 树重建(Tree Reconstruction, UVa 10410)
- 10410 - Tree Reconstruction
- UVa10410 - Tree Reconstruction
- UVA10410 - Tree Reconstruction(队列)
- [UVA10410]Tree Reconstruction[BFS、DFS序建树]
- Aizu - 2564 Tree Reconstruction 并查集
- 4145: [AMPPZ2014]The Prices 状压DP
- [QT]qdebug的使用方法 或者说 使用格式
- Android理解四种启动模式
- 一步一步教你使用.net进行Socket通信
- 九、UiWatcher API 详细介绍
- UVA 10410(p180)----Tree Reconstruction
- hdu 2639 Bone Collector II
- idea 更换编辑器背景图片
- 如何成为一名优秀的全栈工程师
- iOS 中 cell和 label 的自适应高度
- android开发小感
- IOS运行时传递对象或者添加属性
- PHP设计模式之单例模式
- UVA 10491(p326)----Cows and Cars