徐州2019 网络赛

B so easy

写的时候没有想到用map压缩,我好菜啊,看了大佬的代码才明白怎么做

#include<bits/stdc++.h>
using namespace std;
unordered_map<int,int> mp;
int x,y,z,n,m;
int find(int x)
{
    return mp.count(x) ?mp[x]=find(mp[x]) :x;
}
int main()
{
    scanf("%d %d",&x,&y);
    while(y--)
    {
        scanf("%d %d",&n,&m);
        if(n==1)
            mp[m]=m+1;
        else
            printf("%d\n",find(m));
    }
}

 

posted @ 2019-09-08 00:12  大抵一个菜鸡而已  阅读(98)  评论(0编辑  收藏  举报