参考代码:
#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 人评分
简单的a+b (C语言代码)浏览:1137 |
分糖果 (C++代码)浏览:933 |
DNA (C++代码)浏览:671 |
C语言训练-字符串正反连接 (C语言代码)浏览:727 |
C语言程序设计教程(第三版)课后习题6.5 (Java代码)浏览:1251 |
Tom数 (C++代码)浏览:869 |
C二级辅导-进制转换 (C语言代码)浏览:658 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:644 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:790 |
求组合数 (C语言代码)浏览:1207 |