This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 3e5+5;
vector<int> adj[N];
int col[N], visited[6];
int ans = 0;
void dfs(int u){
visited[col[u]] = 1;
ans++;
for(auto v : adj[u]){
if(visited[col[v]]) continue;
int tmp = visited[col[v]];
visited[col[v]] = 1;
dfs(v);
visited[col[v]] = tmp;
}
}
signed main(){
fastio
int n,m,k;
cin >> n >> m >> k;
for(int i = 1;i <= n;i++){
cin >> col[i];
}
for(int i = 0;i < m;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1;i <= n;i++){
visited[col[i]] = 1;
dfs(i);
visited[col[i]] = 0;
}
cout << ans-n << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |