Submission #716429

#TimeUsernameProblemLanguageResultExecution timeMemory
716429AranMasterPaths (BOI18_paths)C++17
23 / 100
3065 ms6316 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector <int> adj[maxn]; int n, k , m; long long ans = 0; int c[maxn] , cl[6] ,dive = 0; bool mark[maxn]; void dfs(int v){ if(dive == k)return; if(mark[v])return; dive++; mark[v] = 1; cl[c[v]]++; if(cl[1] <= 1 and cl[2] <= 1 and cl[3] <= 1 and cl[4] <= 1 and cl[5] <= 1 ){ ans++; for(int u : adj[v]) dfs(u); } mark[v] = 0; cl[c[v]]--; dive--; } int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> m >> k; for(int i = 0; i < n; i++) cin >> c[i + 1]; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for(int i = 0; i < n; i++){ dfs(i + 1); } cout << ans - n << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...