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>
using namespace std;
const int MX = 3e5 + 5;
vector<int>g[MX];
int n, m, k;
int tag[MX];
long long ans = 0;
int cur[6];
void solve(int v, bool first = 0) {
if(cur[tag[v]]) return;
cur[tag[v]] = 1;
if(!first) ++ans;
//cerr<<"v = "<<v<<endl;
for(auto u : g[v]) {
//cerr<<u<<endl;
solve(u);
}
cur[tag[v]] = 0;
}
void PlayGround() {
cin>>n>>m>>k;
for(int i=1; i<=n; ++i) {
cin>>tag[i];
}
for(int i=0; i<m; ++i) {
int u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
//solve(1);
//solve(2, 1);
for(int i=1; i<=n; ++i) {
solve(i, 1);
//cout<<ans<<endl;
}
cout<<ans<<'\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
PlayGround();
return 0;
}
# | 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... |