Codeforces Round #395 (Div. 1) D Timofey and a flat tree (树hash)
2017-02-21 10:44
399 查看
裸的树hash,map维护一下答案即可。
int main()
{
int n;
cin>>n;
for(int i=0;i<=2*n+2;i++){
seed[i]=((LL)rand()<<40)+((LL)rand()<<20)+rand();
}
for(int i=1;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1,-1);
dfs2(1,-1);
root=1;
for(int i=2;i<=n;i++){
if(cnt.find(ha1[i])==cnt.end()){
ans++;
res++;
}
cnt[ha1[i]]++;
}
dfs3(1,-1);
cout<<root<<endl;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<=2*n+2;i++){
seed[i]=((LL)rand()<<40)+((LL)rand()<<20)+rand();
}
for(int i=1;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1,-1);
dfs2(1,-1);
root=1;
for(int i=2;i<=n;i++){
if(cnt.find(ha1[i])==cnt.end()){
ans++;
res++;
}
cnt[ha1[i]]++;
}
dfs3(1,-1);
cout<<root<<endl;
}
相关文章推荐
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- Codeforces Round #395 (Div. 2) -- C. Timofey and a tree(并查集+缩点)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree
- Codeforces Round #395(Div. 2)C. Timofey and a tree【思维+并查集缩点+判定】
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- 【树形DP】Codeforces Round #395 (Div. 2) C. Timofey and a tree
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- 【Codeforces763D】Timofey and a flat tree
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree (树的基础应用)
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)
- C. Timofey and a tree codeforces 395 div2 C
- Codeforces Round #395 (Div. 2) C. Timofey and a tree
- Codeforces Round #395 (Div. 2) C. Timofey and a tree(树的基础应用)