| 比赛 |
csp2025模拟练习1 |
评测结果 |
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE |
| 题目名称 |
通讯网络 |
最终得分 |
0 |
| 用户昵称 |
李奇文 |
运行时间 |
5.591 s |
| 代码语言 |
C++ |
内存使用 |
3.42 MiB |
| 提交时间 |
2025-10-28 11:48:21 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=40,M=155;
int e;
int n,q,fa[N];
int a[M][N][N],f[N][N];
int find(int x){
return fa[x]=(fa[x]==x)?x:find(fa[x]);
}
int main(){
freopen("communication.in","r",stdin);
freopen("communication.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>e>>n>>q;
for(int i=1;i<=q;i++){
int opt,x,y;
cin>>opt>>x;
if(opt==1){
cin>>y;
a[i][x][y]=1;
a[i][y][x]=1;
}else if(opt==2){
cin>>y;
a[i][x][y]=0;
a[i][y][x]=0;
}else{
int ans=0;
memset(f,0,sizeof(f));
for(int j=i-1;j>=i-1-x;j--){
for(int i=1;i<=n;i++){
fa[i]=i;
}
for(int h=0;h<=n;j++){
for(int s=0;s<=n;s++){
if(a[j][h][s]){
int fx=find(h);
int fy=find(s);
fa[fx]=fy;
}
}
}
for(int i=1;i<=n;i++){
ans+=fa[i];
}
}
cout<<ans<<"\n";
}
if(opt!=3){
for(int j=1;j<=n;j++){
for(int k=1;k<=n;k++){
a[i+1][j][k]=a[i][j][k];
}
}
}
}
return 0;
}