社区讨论

数据是不是太弱了?

P1196[NOI2002] 银河英雄传说参与者 2已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@lo8p7a7x
此快照首次捕获于
2023/10/27 22:18
2 年前
此快照最后确认于
2023/10/27 22:18
2 年前
查看原帖
C
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
int a[N],js[N];
int dist[N];
int find(int x){
    if(x!=a[x]){
        int fa=find(a[x]);
        dist[x]+=dist[a[x]];
        a[x]=fa;
    }
    return a[x];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int t;
    cin>>t;
    for(int i=0;i<=N-9;i++){
        js[i]=1;    
        dist[i]=0;
        a[i]=i;
    }
    while(t--){
        string s;
        int x,y;
        cin>>s>>x>>y;
        int fx=find(x),fy=find(y);
        if(s[0]=='M'){
            dist[fx]+=js[fy];
            a[fx]=fy;
            js[fy]+=js[fx];
            js[fx]=0;
        }else{
            if(fx==fy) cout<<abs(dist[x]-dist[y])-1<<endl;
            else cout<<-1<<endl;
        }
    }    
}
洛谷上过了,但是acwing上挂了。 有几篇题解也跟着一起挂了。

回复

4 条回复,欢迎继续交流。

正在加载回复...