結果

問題 No.2563 色ごとのグループ
ユーザー Peach2587
提出日時 2023-12-02 15:22:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 2,836 ms
コンパイル使用メモリ 187,332 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-09-26 18:33:53
合計ジャッジ時間 8,277 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
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