Submission #520647

#TimeUsernameProblemLanguageResultExecution timeMemory
520647Sohsoh84Paths (BOI18_paths)C++17
100 / 100
1033 ms70960 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e6 + 10; int n, m, k, C[MAXN]; ll dp[MAXN], ans = 0; vector<int> adj[MAXN], vert[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> C[i]; C[i]--; vert[C[i]].push_back(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 mask = 0; mask < (1 << k); mask++) { if (__builtin_popcount(mask) < 2) continue; vector<int> vec; for (int i = 0; i < k; i++) if (mask & (1 << i)) vec.push_back(i); int sz = __builtin_popcount(mask); do { memset(dp, 0, sizeof dp); for (int e : vert[vec.front()]) dp[e] = 1; for (int i = 1; i < sz; i++) { int ind = vec[i]; for (int v : vert[ind]) { for (int u : adj[v]) { if (C[u] == vec[i - 1]) { dp[v] += dp[u]; } } if (i == sz - 1) ans += dp[v]; } } } while (next_permutation(all(vec))); } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...