Submission #951706

#TimeUsernameProblemLanguageResultExecution timeMemory
951706mochaPaths (BOI18_paths)C++14
23 / 100
3069 ms14940 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...