結果

問題 No.1390 Get together
ユーザー uzzyuzzy
提出日時 2021-02-12 22:40:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,327 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 164,896 KB
実行使用メモリ 7,188 KB
最終ジャッジ日時 2023-09-27 05:29:23
合計ジャッジ時間 4,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,376 KB
testcase_01 AC 4 ms
5,304 KB
testcase_02 AC 3 ms
5,304 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 3 ms
5,624 KB
testcase_15 AC 3 ms
5,328 KB
testcase_16 AC 45 ms
6,916 KB
testcase_17 AC 44 ms
6,916 KB
testcase_18 AC 43 ms
7,060 KB
testcase_19 AC 54 ms
6,944 KB
testcase_20 AC 56 ms
6,916 KB
testcase_21 AC 53 ms
6,860 KB
testcase_22 AC 50 ms
6,948 KB
testcase_23 AC 51 ms
6,992 KB
testcase_24 AC 55 ms
6,900 KB
testcase_25 AC 53 ms
7,000 KB
testcase_26 AC 52 ms
6,868 KB
testcase_27 AC 59 ms
6,872 KB
testcase_28 AC 54 ms
7,188 KB
testcase_29 AC 53 ms
6,916 KB
testcase_30 AC 56 ms
6,996 KB
testcase_31 AC 53 ms
6,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int SZ = 500000;
class UF {
public:
	int P[SZ + 1], kazu[SZ + 1];
	UF() : P() {
		rep1(i, SZ) P[i] = -1;
	}
	int find(int A) {
		if (P[A] < 0) return A;
		return P[A] = find(P[A]);
	}
	bool unite(int A, int B) {
		int a = find(A);
		int b = find(B);
		if (a == b) return false;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		kazu[a] += kazu[b];
		P[b] = a;
		return true;
	}
} uf;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, M;
	cin >> N >> M;

	rep1(i, N) uf.kazu[i] = 1;
	rep1(i, M) uf.kazu[i + 200000] = 0;

	rep1(i, N) {
		int b, c;
		cin >> b >> c;
		uf.unite(b, c + 200000);
	}

	int kotae = 0;
	rep1(i, N) {
		if (uf.find(i) == i && uf.kazu[i]) {
			kotae += uf.kazu[i] - 1;
		}
	}
	co(kotae);

	Would you please return 0;
}
0