結果

問題 No.2563 色ごとのグループ
ユーザー FleoFleo
提出日時 2023-12-04 21:25:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 176,100 KB
実行使用メモリ 16,140 KB
最終ジャッジ日時 2023-12-04 21:25:20
合計ジャッジ時間 6,334 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 3 ms
6,548 KB
testcase_16 AC 3 ms
6,548 KB
testcase_17 AC 3 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 5 ms
6,548 KB
testcase_20 AC 12 ms
6,548 KB
testcase_21 AC 8 ms
6,548 KB
testcase_22 AC 7 ms
6,548 KB
testcase_23 AC 12 ms
6,548 KB
testcase_24 AC 106 ms
6,548 KB
testcase_25 AC 86 ms
6,548 KB
testcase_26 AC 119 ms
8,064 KB
testcase_27 AC 99 ms
10,032 KB
testcase_28 AC 143 ms
8,576 KB
testcase_29 AC 196 ms
10,380 KB
testcase_30 AC 183 ms
10,380 KB
testcase_31 AC 185 ms
10,380 KB
testcase_32 AC 183 ms
10,380 KB
testcase_33 AC 245 ms
16,012 KB
testcase_34 AC 255 ms
16,012 KB
testcase_35 AC 271 ms
16,012 KB
testcase_36 AC 249 ms
16,140 KB
testcase_37 AC 242 ms
16,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Ul = unsigned long long;
using cl = const ll;
using VI = vector<int>;
using VS = vector<string>;
using VC = vector<char>;
using VL = vector<ll>;
using VU = vector<Ul>;
using VB = vector<bool>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
void fix(int a){cout << fixed << setprecision(a);}
template<class t,class u> bool chmax(t&a,u b) {if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b) {if(b<a){a=b;return true;}else return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
    int N,M;
    cin>>N>>M;
    VI C(N),dist(N,-1),count(N,-1);
    vector<VI> G(N);
    rep(i,N) cin>>C[i];
    rep(i,M)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        if(C[a]==C[b])
        {
            G[a].push_back(b);
            G[b].push_back(a);
        }
        else continue;
    }
    queue<int> que;
    rep(i,N)
    {
        if(dist[i]==-1)
        {
            que.push(i);
            dist[i]=0;
            count[C[i]-1]++;
        }
        while(!que.empty())
        {
            int t=que.front();
            que.pop();
            rep(j,G[t].size())
            {            
                if(dist[G[t][j]]==-1)
                {
                    que.push(G[t][j]);
                    dist[G[t][j]]=0;
                }
            }
        }
    }
    int Ans=0;
    rep(i,N)
    {
        if(count[i]>=0) Ans+=count[i];
    }
    cout<<Ans;
}
0