Submission #563670

#TimeUsernameProblemLanguageResultExecution timeMemory
563670colossal_pepePaths (BOI18_paths)C++17
53 / 100
791 ms728676 KiB
#include <iostream> #include <vector> using namespace std; using ll = long long; int n, m, k, c[300005]; ll dp[100005][6][6][6][6]; vector<vector<int>> g; ll solve() { ll ans = 0; if (k < 2) return ans; for (int u = 0; u < n; u++) { for (int v : g[u]) { dp[u][c[v]][0][0][0]++; } for (int c1 = 1; c1 <= k; c1++) { if (c1 == c[u]) continue; ans += dp[u][c1][0][0][0]; } } if (k < 3) return ans; for (int u = 0; u < n; u++) { for (int v : g[u]) { for (int c1 = 1; c1 <= k; c1++) { dp[u][c[v]][c1][0][0] += dp[v][c1][0][0][0]; } } for (int c1 = 1; c1 <= k; c1++) { if (c1 == c[u]) continue; for (int c2 = 1; c2 <= k; c2++) { if (c2 == c[u] or c2 == c1) continue; ans += dp[u][c1][c2][0][0]; } } } if (k < 4) return ans; for (int u = 0; u < n; u++) { for (int v : g[u]) { for (int c1 = 1; c1 <= k; c1++) { for (int c2 = 1; c2 <= k; c2++) { dp[u][c[v]][c1][c2][0] += dp[v][c1][c2][0][0]; } } } for (int c1 = 1; c1 <= k; c1++) { if (c1 == c[u]) continue; for (int c2 = 1; c2 <= k; c2++) { if (c2 == c[u] or c2 == c1) continue; for (int c3 = 1; c3 <= k; c3++) { if (c3 == c[u] or c3 == c1 or c3 == c2) continue; ans += dp[u][c1][c2][c3][0]; } } } } if (k < 5) return ans; for (int u = 0; u < n; u++) { for (int v : g[u]) { for (int c1 = 1; c1 <= k; c1++) { for (int c2 = 1; c2 <= k; c2++) { for (int c3 = 1; c3 <= k; c3++) { dp[u][c[v]][c1][c2][c3] += dp[v][c1][c2][c3][0]; } } } } for (int c1 = 1; c1 <= k; c1++) { if (c1 == c[u]) continue; for (int c2 = 1; c2 <= k; c2++) { if (c2 == c[u] or c2 == c1) continue; for (int c3 = 1; c3 <= k; c3++) { if (c3 == c[u] or c3 == c1 or c3 == c2) continue; for (int c4 = 1; c4 <= k; c4++) { if (c4 == c[u] or c4 == c1 or c4 == c2 or c4 == c3) continue; ans += dp[u][c1][c2][c3][c4]; } } } } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; g.resize(n); for (int i = 0; i < n; i++) { cin >> c[i]; } while (m--) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } cout << solve() << 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...