2 条题解

  • 1
    @ 2022-1-19 11:04:18

    #include using namespace std; int n,m,a[10010],opt,x,y; void init(){ for(int i=1;i<=n;i++){ a[i]=i; } } int find(int x){ if(a[x]x)return x; a[x]=find(a[x]); return a[x]; } int main(){ cin>>n>>m; init(); for(int i=1;i<=m;i++){ cin>>opt>>x>>y; x=find(x); y=find(y); if(opt1){ a[x]=y; }else{ if(x==y){ cout<<"Y"<<endl; }else{ cout<<"N"<<endl; } } } }

    信息

    ID
    1347
    时间
    500ms
    内存
    64MiB
    难度
    5
    标签
    递交数
    22
    已通过
    15
    上传者