POJ 1470 LCA
来源:互联网 发布:云计算的特征是什么 编辑:程序博客网 时间:2024/05/22 01:17
哎 越来越不行了 把“%1s"写成”%s" 错了n次 坑爹啊
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespace std;const int maxn=1007;vector<int> g[maxn];vector<int> un[maxn];int father[maxn];bool vis[maxn];int cnt[maxn];int find(int x){ if(father[x]!=x) { father[x]=find(father[x]); } return father[x];}void tarjan(int u){vis[u]=true;father[u]=u;int i,v;for(i=0;i<un[u].size();i++){v=un[u][i];if(vis[v]){cnt[find(v)]++;}}for(i=0;i<g[u].size();i++){v=g[u][i];if(!vis[v]){tarjan(v);father[v]=u;}}}int main(){int n,m,u,v;char stmp1[20],stmp2[20];while(~scanf("%d",&n)){int i,j;for(i=0;i<maxn;i++){g[i].clear();un[i].clear();}memset(father,0,sizeof(father));for(i=0;i<n;i++){scanf("%d%2s%d%1s",&u,stmp1,&m,stmp2);for(j=0;j<m;j++){scanf("%d",&v);g[u].push_back(v);father[v]++;}}scanf("%d",&m);for(i=0;i<m;i++){scanf("%1s%d%d%1s",stmp1,&u,&v,stmp2);un[u].push_back(v);un[v].push_back(u);}for(i=1;i<=n;i++){if(father[i]==0){break;}}memset(vis,0,sizeof(vis));memset(cnt,0,sizeof(cnt));tarjan(i);for(i=1;i<=n;i++){if(cnt[i]){ printf("%d:%d\n",i,cnt[i]);}}}return 0;}
- poj 1470--tarjan--LCA
- POJ 1470 LCA
- poj 1470(LCA)
- poj 1470(LCA模板题)
- POJ 1470 LCA 公共祖先
- poj 1470(LCA RE)
- poj 1470 LCA 离线算法
- poj 1470 LCA基础题
- poj 1470 LCA倍增 裸
- POJ-1470 Closest Common Ancestors【LCA】
- POJ-1470 Closest Common Ancestors【LCA】
- POJ 1470 Closest Common Ancestors [LCA+RMQ]
- poj 1470 Closest Common Ancestors(LCA)
- poj--1470--Closest Common Ancestors--LCA
- POJ 1470 Closest Common Ancestors LCA题解
- Closest Common Ancestors - POJ 1470 LCA
- poj 1470 Closest Common Ancestors(LCA)
- 【LCA】 POJ 1470 Closest Common Ancestors
- Android declare-styleable:自定义控件的属性(attr.xml,TypedArray)的使用
- 提高自己的职业技能:性能测试
- [10月1日的脚本] 移除Windows8应用商店中的应用程序
- 求二叉树的“胖”度
- C++:静态联编和动态联编
- POJ 1470 LCA
- c++中的显示转换
- java剪切图片
- C++的显式类型转换
- C++中的类型转换
- 从一道面试题谈linux下fork的运行机制
- Delphi 的接口机制——接口操作的编译器实现过程(1)
- Android中刻度尺实现
- ios获得通讯录中联系人的所有属性