結果

問題 No.2563 色ごとのグループ
ユーザー hiro1729hiro1729
提出日時 2023-12-02 14:46:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 393 bytes
コンパイル時間 3,418 ms
コンパイル使用メモリ 259,260 KB
実行使用メモリ 23,388 KB
最終ジャッジ日時 2023-12-02 14:47:03
合計ジャッジ時間 8,206 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 17 ms
6,676 KB
testcase_21 AC 11 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 14 ms
6,676 KB
testcase_24 AC 132 ms
11,136 KB
testcase_25 AC 117 ms
12,288 KB
testcase_26 AC 174 ms
16,768 KB
testcase_27 AC 179 ms
22,256 KB
testcase_28 AC 197 ms
18,380 KB
testcase_29 AC 305 ms
23,388 KB
testcase_30 AC 280 ms
23,388 KB
testcase_31 AC 275 ms
23,372 KB
testcase_32 AC 273 ms
23,368 KB
testcase_33 AC 213 ms
12,844 KB
testcase_34 AC 205 ms
12,844 KB
testcase_35 AC 232 ms
12,844 KB
testcase_36 AC 209 ms
12,844 KB
testcase_37 AC 211 ms
12,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/dsu>
using namespace atcoder;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> c(n); for (int i = 0; i < n; i++) cin >> c[i];
	set<int> s;
	for (int i: c) s.insert(i);
	dsu uf(n);
	while (m--) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		if (c[u] == c[v]) uf.merge(u, v);
	}
	cout << uf.groups().size() - s.size() << '\n';
}
0