Submission #441395

#TimeUsernameProblemLanguageResultExecution timeMemory
441395sam571128Paths (BOI18_paths)C++17
23 / 100
3093 ms14624 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...