Submission #1111704

#TimeUsernameProblemLanguageResultExecution timeMemory
1111704ortsacPaths (BOI18_paths)C++17
100 / 100
865 ms23216 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n, m, k; vector<int> ord; const int MAXN = 3e5 + 10; vector<int> adj[MAXN]; int cor[MAXN]; int dp[MAXN]; int t; void calc(int node, int i) { if (dp[node] != -1) return; if (i == (t - 1)) { dp[node] = 1; return; } dp[node] = 0; for (auto u : adj[node]) { if (cor[u] == ord[i + 1]) { calc(u, i + 1); dp[node] += dp[u]; } } } int32_t main() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> cor[i]; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } int ans = 0; for (int mask = 1; mask < (1LL << k); mask++) { ord.clear(); for (int i = 0; i < k; i++) { if (mask & (1LL << i)) ord.push_back(i + 1); } t = ord.size(); if (t == 1) continue; do { // do it now!! //for (auto u : ord) cout << u << " "; //cout << "\n"; int currans = 0; memset(dp, -1, sizeof dp); for (int i = 1; i <= n; i++) { if (cor[i] == ord[0]) { calc(i, 0); currans += dp[i]; } } //cout << "ans " << currans << "\n"; ans += currans; } while (next_permutation(ord.begin(), ord.end())); } cout << ans << "\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...