参考代码:
#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 人评分
sizeof的大作用 (C语言代码)浏览:1448 |
小九九 (C语言描述,不看要求真坑爹)浏览:984 |
时间转换 (C语言代码)浏览:624 |
C语言程序设计教程(第三版)课后习题12.2 (C语言代码)浏览:753 |
简单的a+b (C语言代码)浏览:628 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:484 |
字符逆序 (C语言代码)浏览:504 |
C语言训练-最大数问题 (C语言代码)浏览:584 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:483 |
母牛的故事 (C语言代码)浏览:476 |