結果

問題 No.2563 色ごとのグループ
ユーザー 👑 deuteridayodeuteridayo
提出日時 2023-09-20 21:27:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 907 bytes
コンパイル時間 3,555 ms
コンパイル使用メモリ 225,944 KB
実行使用メモリ 17,204 KB
最終ジャッジ日時 2023-12-02 14:00:30
合計ジャッジ時間 9,596 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 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 2 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 2 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 4 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 15 ms
6,676 KB
testcase_21 AC 10 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 13 ms
6,676 KB
testcase_24 AC 119 ms
7,296 KB
testcase_25 AC 109 ms
7,936 KB
testcase_26 AC 146 ms
10,240 KB
testcase_27 AC 136 ms
13,000 KB
testcase_28 AC 168 ms
11,040 KB
testcase_29 AC 227 ms
13,620 KB
testcase_30 AC 231 ms
13,620 KB
testcase_31 AC 228 ms
13,492 KB
testcase_32 AC 229 ms
13,492 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
using lint = long long;

int main(){
    int n, m; 
    cin >> n >> m;
    int c[n];
    vector<vector<int>>cc(n+1);
    for(int i = 0; i < n; i++) {
        cin >> c[i];
        cc[c[i]].push_back(i);
    }
    
    atcoder::dsu d(n);
    for(int i = 0; i < m; i++) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        if(c[u] == c[v])d.merge(u, v);
    }

    // O(N^2) TLE解法
    lint ans = 0;
    for(int i = 0; i <= n; i++) {
       for(int j = 0; j < cc[i].size(); j++) {
            for(int k = j+1; k < cc[i].size(); k++) {
                if(!d.same(cc[i][j], cc[i][k])) {
                    d.merge(cc[i][j], cc[i][k]);
                    ans++;
                }
            }
        }
    }
    cout << ans;
    
}

0