結果
| 問題 | No.2563 色ごとのグループ | 
| コンテスト | |
| ユーザー |  nonon | 
| 提出日時 | 2023-12-02 18:33:23 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 97 ms / 2,000 ms | 
| コード長 | 610 bytes | 
| コンパイル時間 | 2,174 ms | 
| コンパイル使用メモリ | 206,740 KB | 
| 最終ジャッジ日時 | 2025-02-18 06:08:47 | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 35 | 
ソースコード
#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
int N,M,C[2<<17];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>M;
    for(int i=0;i<N;i++)cin>>C[i];
    vector<int>B(N);
    for(int i=0;i<N;i++)B[i]=C[i];
    sort(B.begin(),B.end());
    B.erase(unique(B.begin(),B.end()),B.end());
    atcoder::dsu uf(N);
    for(;M--;)
    {
        int u,v;
        cin>>u>>v;
        u--,v--;
        if(C[u]==C[v])
        {
            uf.merge(u,v);
            // cout << u+1 << " " << v+1 << endl;
        }
    }
    cout << uf.groups().size()-B.size() << endl;
}
            
            
            
        