結果

問題 No.2563 色ごとのグループ
ユーザー strawberry0929strawberry0929
提出日時 2023-12-02 15:22:33
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,676 bytes
コンパイル時間 4,781 ms
コンパイル使用メモリ 311,036 KB
実行使用メモリ 13,548 KB
最終ジャッジ日時 2023-12-02 15:22:50
合計ジャッジ時間 8,794 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 RE -
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 3 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 WA -
testcase_20 AC 13 ms
6,548 KB
testcase_21 AC 7 ms
6,548 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 66 ms
7,296 KB
testcase_25 AC 82 ms
7,936 KB
testcase_26 AC 127 ms
10,224 KB
testcase_27 WA -
testcase_28 AC 137 ms
10,952 KB
testcase_29 AC 186 ms
13,548 KB
testcase_30 AC 187 ms
13,548 KB
testcase_31 AC 187 ms
13,548 KB
testcase_32 AC 186 ms
13,548 KB
testcase_33 AC 189 ms
10,808 KB
testcase_34 WA -
testcase_35 AC 177 ms
10,808 KB
testcase_36 WA -
testcase_37 AC 184 ms
10,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using mint = modint998244353;
using ll = long long;
using lb = long double;
using VI = vector<int>;
using VL = vector<ll>;
using P = pair<int, int>;
inline void scan(){}
template<class Head,class... Tail>
inline void scan(Head&head,Tail&... tail){std::cin>>head;scan(tail...);}
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define LB(...) lb __VA_ARGS__;scan(__VA_ARGS__)
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
template<class ll> inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return 1; } return 0; }template<class ll> inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>
std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T>
std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
//_
int main(){
  INT(n, m);
  vector<int> c(n);
  cin >> c;
  dsu uf(n);
  rep(i, 0, n){
    INT(u, v);
    u--;
    v--;
    if(c[u] == c[v])uf.merge(u, v);
  }
  vector<vector<int>> g(n);
  rep(i, 0, n){
    g[c[i] - 1].push_back(i);
  }
  int ans = 0;
  rep(i, 0, n){
    rep(j, 1, size(g[i])){
    if(!uf.same(g[i][0], g[i][j])){
      uf.merge(g[i][0], g[i][j]);
      ans++;
    }
    }
  }
  cout << ans << endl;
}
0