結果

問題 No.2563 色ごとのグループ
ユーザー gabriel55_gabriel55_
提出日時 2023-12-02 15:04:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 2,051 bytes
コンパイル時間 4,450 ms
コンパイル使用メモリ 267,824 KB
実行使用メモリ 14,588 KB
最終ジャッジ日時 2023-12-02 15:04:09
合計ジャッジ時間 7,308 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 6 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 3 ms
6,676 KB
testcase_23 AC 5 ms
6,676 KB
testcase_24 AC 39 ms
7,680 KB
testcase_25 AC 34 ms
8,448 KB
testcase_26 AC 49 ms
10,880 KB
testcase_27 AC 52 ms
14,064 KB
testcase_28 AC 57 ms
11,864 KB
testcase_29 AC 81 ms
14,588 KB
testcase_30 AC 82 ms
14,588 KB
testcase_31 AC 82 ms
14,588 KB
testcase_32 AC 78 ms
14,588 KB
testcase_33 AC 68 ms
11,980 KB
testcase_34 AC 67 ms
11,980 KB
testcase_35 AC 65 ms
11,980 KB
testcase_36 AC 69 ms
11,980 KB
testcase_37 AC 67 ms
11,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#if !__INCLUDE_LEVEL__
#include __FILE__

int main() {
   ll n, m;
   cin >> n >> m;
   vector<ll> co(n);
   vector c(n, vector<ll>());
   rep(i,n) {
      ll a;
      cin >> a;
      a--;
      co[i] = a;
      c[a].emplace_back(i);
   }
   dsu uf(n);
   rep(i,m) {
      ll a, b;
      cin >> a >> b;
      a--; b--;
      if(co[a] == co[b]) uf.merge(a, b);
   }
   ll ans = 0;
   rep(i,n) {
      m_99(j,1,c[i].size()) {
         if(!uf.same(c[i][j], c[i][j-1])) {
            uf.merge(c[i][j], c[i][j-1]);
            ans++;
         }
      }
   }
   cout << ans << '\n';
}

/*---------------------------------------------------------------------------------------------------
      ○______
       ||      |
       ||   ●   |
       ||      |
        || ̄ ̄ ̄ ̄ ̄
       ||  君が代は
   ∧__,,∧||  千代に八千代に
  ( `・ω・||    さざれ石の巌となりて
   ヽ  つ0     こけのむすまで
   し―-J
---------------------------------------------------------------------------------------------------*/

#else
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using P = pair<ll, ll>;
#define fi first
#define se second
#define m_99(i,a,b) for (ll i = a, i##_range = (b); i < i##_range; i++)
#define REP(i,a,b) m_99(i,a,b)
#define rep(i,a) m_99(i,0,a)
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
#ifdef _DEBUG
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
struct initialise { initialise() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }__INI__;
const ll inf = 1LL << 60;
const ll dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
#endif
0