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;
int n, m, K;
int a[mx];
vector<int> g[mx];
bool vis[mx];
set<int> st;
long long cnt;
void dfs(int x) {
vis[x] = 1;
st.insert(a[x]);
cnt++;
for (int i:g[x]) {
if (!st.count(a[i]) and !vis[i]) {
dfs(i);
}
}
vis[x] = 0;
st.erase(a[x]);
}
int main() {
cin >> n >> m >> K;
for (int i=1;i<=n;i++) {
cin >> a[i];
}
for (int i=1;i<=m;i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i=1;i<=n;i++) {
dfs(i);
}
cout << cnt - 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... |