結果
| 問題 |
No.2563 色ごとのグループ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-04 21:22:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,519 bytes |
| コンパイル時間 | 1,834 ms |
| コンパイル使用メモリ | 175,244 KB |
| 実行使用メモリ | 16,128 KB |
| 最終ジャッジ日時 | 2024-09-26 23:14:14 |
| 合計ジャッジ時間 | 6,191 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 5 RE * 5 |
ソースコード
#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]]++;
}
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;
}