結果

問題 No.2563 色ごとのグループ
ユーザー Peach2587Peach2587
提出日時 2023-12-02 15:22:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 2,568 ms
コンパイル使用メモリ 188,000 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2023-12-02 15:22:36
合計ジャッジ時間 6,959 ms
ジャッジサーバーID
(参考情報)
judge9 / 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 1 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 1 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 17 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 13 ms
6,676 KB
testcase_24 AC 136 ms
9,600 KB
testcase_25 AC 125 ms
10,624 KB
testcase_26 AC 183 ms
14,208 KB
testcase_27 AC 200 ms
18,688 KB
testcase_28 AC 243 ms
15,488 KB
testcase_29 AC 307 ms
19,584 KB
testcase_30 AC 304 ms
19,584 KB
testcase_31 AC 297 ms
19,456 KB
testcase_32 AC 334 ms
19,456 KB
testcase_33 AC 176 ms
7,396 KB
testcase_34 AC 186 ms
7,396 KB
testcase_35 AC 174 ms
7,396 KB
testcase_36 AC 203 ms
7,396 KB
testcase_37 AC 186 ms
7,396 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:31:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   31 |   for(auto [k, v] : mp){
      |            ^

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/dsu>
#include <boost/rational.hpp>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
const double pi = 3.14159265359879323846264338327950288419;
const ll INF = 9 * 1e18;
using p = pair<ll, ll>;

int main() {
  int n, m; cin >> n >> m;
  vector<ll> color(n);
  map<int, vector<int>> mp;
  for(int i = 0; i < n; i++){
    cin >> color[i];
    mp[color[i]].push_back(i);
  }
  
  dsu d(n);
  while(m--){
    int u, v; cin >> u >> v;
    u--; v--;
    if(color[u] == color[v]) d.merge(u, v);
  }
  
  ll cnt = 0;
  for(auto [k, v] : mp){
    //cerr << k << " : ";
    for(auto x : v) {
      //cerr << x << " ";
      if(d.same(v[0], x)) continue;
      d.merge(v[0], x);
      cnt++;
    }
    //cerr << endl;
  }
  
  cout << cnt << endl;
}
0