結果

問題 No.2563 色ごとのグループ
ユーザー hanagehanage
提出日時 2023-12-02 15:56:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 668 bytes
コンパイル時間 3,776 ms
コンパイル使用メモリ 211,772 KB
実行使用メモリ 17,452 KB
最終ジャッジ日時 2023-12-02 15:57:03
合計ジャッジ時間 6,339 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 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 2 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 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 12 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 12 ms
6,676 KB
testcase_24 AC 103 ms
8,832 KB
testcase_25 AC 86 ms
9,600 KB
testcase_26 AC 125 ms
12,800 KB
testcase_27 AC 119 ms
16,640 KB
testcase_28 AC 142 ms
13,944 KB
testcase_29 AC 188 ms
17,452 KB
testcase_30 AC 185 ms
17,452 KB
testcase_31 AC 184 ms
17,452 KB
testcase_32 AC 185 ms
17,452 KB
testcase_33 AC 183 ms
12,844 KB
testcase_34 AC 204 ms
12,844 KB
testcase_35 AC 182 ms
12,844 KB
testcase_36 AC 186 ms
12,844 KB
testcase_37 AC 190 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];
  }
  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 + 1, 0);
  for (auto x : g) {
    // for (auto y : x) cout << y << " ";
    // cout << endl;
    cnt[C[x[0]]]++;
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (cnt[i] > 0) {
      ans += cnt[i] - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
0