Codeforces Round #395 (Div. 1) D Timofey and a flat tree (树hash)

来源:互联网 发布:跑步内衣 推荐 知乎 编辑:程序博客网 时间:2024/05/22 13:10

裸的树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;}


0 0