結果
| 問題 | No.2563 色ごとのグループ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-02 15:32:35 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 173 ms / 2,000 ms |
| コード長 | 708 bytes |
| 記録 | |
| コンパイル時間 | 3,038 ms |
| コンパイル使用メモリ | 278,816 KB |
| 実行使用メモリ | 25,344 KB |
| 最終ジャッジ日時 | 2026-07-03 03:26:58 |
| 合計ジャッジ時間 | 6,658 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
const ll mod = 1000000007;
//const ll mod = 998244353;
int n, m, c[200009], u[200009], v[200009];
set<int>S[200009];
int main() {
cin >> n >> m;
dsu UF(n + 1);
for (int i = 1; i <= n; i++) {
cin >> c[i];
S[c[i]].insert(i);
}
for (int i = 1; i <= m; i++) {
cin >> u[i] >> v[i];
if(c[u[i]]==c[v[i]])UF.merge(u[i], v[i]);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ll cnt = 0, par = 0;
for (auto& s : S[i]) {
cnt++;
if (cnt == 1) {
par = s;
continue;
}
if (UF.same(par, s) == false) {
ans++;
UF.merge(par, s);
}
}
}
cout << ans << endl;
}