Submission #927916

#TimeUsernameProblemLanguageResultExecution timeMemory
927916TAhmed33Paths (BOI18_paths)C++98
100 / 100
352 ms172392 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[300001][1 << 6]; int a[300001], n, m, k; vector <int> adj[300001]; ll ans (int pos, int mask) { ll &ret = dp[pos][mask]; if (ret != -1) return ret; ret = 1; for (auto j : adj[pos]) { if (!((mask >> a[j]) & 1)) { ret += ans(j, mask ^ (1 << a[j])); } } return ret; } int main () { memset(dp, -1, sizeof(dp)); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i]--; } for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; adj[x].push_back(y); adj[y].push_back(x); } ll sum = 0; for (int i = 1; i <= n; i++) { sum += ans(i, 1 << a[i]); } sum -= n; cout << sum << '\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...