专栏文章

abc399C

个人记录参与者 1已保存评论 0

文章操作

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

当前评论
0 条
当前快照
1 份
快照标识符
@mipr4bwz
此快照首次捕获于
2025/12/03 16:34
3 个月前
此快照最后确认于
2025/12/03 16:34
3 个月前
查看原文
CPP
#include<bits/stdc++.h>
using namespace std;
long long read(){
	long long x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
void write(long long x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9){
		write(x/10);
	}
	putchar(x%10+'0');
	return ;
}
vector<int> tu[200005];
int fa[200005];
int find(int x){
	if(fa[x]==x){
		return x;
	}
	return fa[x]=find(fa[x]);
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n=read(),m=read();
	int ans=0;
	for(int i=1;i<=n;i++){
		fa[i]=i;
	}
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		if(find(fa[u])==find(fa[v])){
			ans++;
			continue ;
		}
		tu[u].push_back(v);
		tu[v].push_back(u);
		fa[find(fa[v])]=fa[u];
	}
	write(ans);
	return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...