参考代码:
#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语言代码)--此题的题目描述有问题浏览:1817 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:575 |
【排队买票】 (C语言代码)浏览:900 |
WU-输出九九乘法表 (C++代码)浏览:1671 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:902 |
P1000 (C语言代码)浏览:877 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:1170 |
Pascal三角 (C语言代码)浏览:652 |
良心推荐——>题解1049:C语言程序设计教程(第三版)课后习题11.1 (C语言描述——简单明了,时间复杂度低)浏览:1287 |
敲七 (C语言代码)浏览:2701 |