您的位置:首页 > Web前端

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM