参考代码:
#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 人评分
母牛的故事 (C语言代码)浏览:668 |
这可能是一个假的冒泡法浏览:985 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:518 |
计算质因子 (C++代码)浏览:1617 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1242 |
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:5229 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:798 |
【金明的预算方案】 (C++代码)浏览:935 |
【金明的预算方案】 (C++代码)浏览:838 |
The 3n + 1 problem (C语言代码)浏览:548 |