HzuWHF


私信TA

用户名:I7I08I9047

访问量:76448

签 名:

我RUN了

等  级
排  名 18
经  验 20463
参赛次数 13
文章发表 127
年  龄 3
在职情况 学生
学  校 贺州学院
专  业

  自我简介:



参考代码:

#include<bits/stdc++.h>
#define Inf 0x3F3F3F3F
#define Loc freopen("baka.in", "r", stdin)
typedef long long LL;
using namespace std;

LL Read() {
	LL ___ = 0, __ = 1; char _ = getchar();
	while (_ < 48 || _ > 57)  if (_ == 45) __ = -1, _ = getchar();
	while (_ >= 48 && _ <= 57) ___ = ___ * 10 + _ - 48, _ = getchar();
	return ___ * __;
}

const int SIZE = 1E6 + 7;
int Father[SIZE], Tot;

int find(int L) {
	return L == Father[L] ? L : Father[L] = find(Father[L]);
}

void Link(int L, int R) {
	Father[find(L)] = find(R);
}

int main() {
	int N = Read(), M = Read(); Tot = N * M;
	for (int pos = 1; pos <= Tot; pos++)
		Father[pos] = pos;
	M = Read();
	while (M--) {
		int L = Read(), R = Read(); Link(L, R);
	}
	int ans = 0;
	for (int pos = 1; pos <= Tot; pos++)
		ans += Father[pos] == pos;
	cout << ans << endl;
}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区