徐州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));
    }
}

猜你喜欢

转载自www.cnblogs.com/wakaka12345/p/11484031.html