結果

問題 No.2563 色ごとのグループ
ユーザー yansi819yansi819
提出日時 2024-03-16 14:27:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 456 bytes
コンパイル時間 2,483 ms
コンパイル使用メモリ 216,884 KB
実行使用メモリ 23,372 KB
最終ジャッジ日時 2024-03-16 14:27:15
合計ジャッジ時間 9,851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 6 ms
6,676 KB
testcase_20 AC 18 ms
6,676 KB
testcase_21 AC 10 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 14 ms
6,676 KB
testcase_24 AC 139 ms
11,136 KB
testcase_25 AC 125 ms
12,288 KB
testcase_26 AC 192 ms
16,768 KB
testcase_27 AC 222 ms
22,280 KB
testcase_28 AC 217 ms
18,304 KB
testcase_29 AC 304 ms
23,372 KB
testcase_30 AC 301 ms
23,372 KB
testcase_31 AC 328 ms
23,356 KB
testcase_32 AC 307 ms
23,352 KB
testcase_33 AC 209 ms
12,828 KB
testcase_34 AC 203 ms
12,828 KB
testcase_35 AC 205 ms
12,828 KB
testcase_36 AC 212 ms
12,828 KB
testcase_37 AC 208 ms
12,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N, M;
int C[202020];
int u, v;
map<int, int> mp;

int main(void){
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    mp[C[i]]++;
  }
  dsu uf(N);
  for (int i = 0; i < M; i++) {
    cin >> u >> v;
    u--, v--;
    if (C[u] == C[v]) uf.merge(u, v);
  }
  cout << uf.groups().size() - mp.size() << endl;
  return 0;
}
0