結果
| 問題 |
No.2563 色ごとのグループ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-02 15:01:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 660 bytes |
| コンパイル時間 | 2,279 ms |
| コンパイル使用メモリ | 205,000 KB |
| 最終ジャッジ日時 | 2025-02-18 04:09:24 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 6 RE * 2 |
ソースコード
#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];
}
dsu Union(N);
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
u--, v--;
if (C[u] == C[v]) {
Union.merge(u, v);
}
}
auto g = Union.groups();
vector<int> cnt(N);
for (auto x : g) {
// for (auto y : x) cout << y << " ";
// cout << endl;
cnt[C[x[0]]]++;
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (cnt[i] > 0) {
ans += cnt[i] - 1;
}
}
cout << ans << endl;
return 0;
}