結果

問題 No.2563 色ごとのグループ
ユーザー hanagehanage
提出日時 2023-12-02 15:01:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 2,397 ms
コンパイル使用メモリ 211,556 KB
実行使用メモリ 17,452 KB
最終ジャッジ日時 2023-12-02 15:01:30
合計ジャッジ時間 6,943 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 WA -
testcase_15 RE -
testcase_16 AC 3 ms
6,548 KB
testcase_17 WA -
testcase_18 AC 3 ms
6,548 KB
testcase_19 RE -
testcase_20 AC 15 ms
6,548 KB
testcase_21 WA -
testcase_22 AC 8 ms
6,548 KB
testcase_23 AC 13 ms
6,548 KB
testcase_24 AC 114 ms
8,832 KB
testcase_25 AC 94 ms
9,600 KB
testcase_26 AC 135 ms
12,800 KB
testcase_27 AC 117 ms
16,640 KB
testcase_28 AC 154 ms
13,944 KB
testcase_29 AC 211 ms
17,452 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 206 ms
17,452 KB
testcase_33 AC 208 ms
12,844 KB
testcase_34 AC 201 ms
12,844 KB
testcase_35 AC 212 ms
12,844 KB
testcase_36 AC 207 ms
12,844 KB
testcase_37 AC 207 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);
  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;
}
0