50ptsWA求调(玄2关)
查看原帖
50ptsWA求调(玄2关)
1475943
libu2333楼主2025/2/7 13:04

rt 代码如下(带路径压缩)

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5;
int n,m;
int s[N];
void init(){
    for(int i=1;i<=n;i++) s[i]=i;
}
int find_set(int x){
    return x==s[x]?x:s[x]=find_set(s[x]);
}
signed main(){
    cin>>n>>m;
    init();
    while(m--){
        int x,y,z;
        cin>>z>>x>>y;
        int xx=find_set(x),yy=find_set(y);
        if(z==1) s[xx]=yy;
        else if(z==2) cout<<(xx==yy?'Y':'N')<<endl; 
    }
    return 0;
}
2025/2/7 13:04
加载中...