# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268468 | ducdev | Paths (BOI18_paths) | C++17 | 272 ms | 52272 KiB |
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 3e5;
const int MOD = 1e9 + 7;
int n, m, k;
int color[MAX_N + 5];
ll dp[1 << 5][MAX_N + 5];
vector<int> adj[MAX_N + 5];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("MAIN.INP", "r")) {
freopen("MAIN.INP", "r", stdin);
freopen("MAIN.OUT", "w", stdout);
};
cin >> n >> m >> k;
for (int u = 1; u <= n; u++) {
cin >> color[u];
color[u]--;
};
while (m--) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
};
ll res = 0;
for (int u = 1; u <= n; u++) dp[1 << color[u]][u] = 1;
for (int mask = 1; mask < (1 << k); mask++) {
for (int u = 1; u <= n; u++) {
for (int v : adj[u]) {
if (mask >> color[v] & 1) continue;
dp[mask ^ (1 << color[v])][v] += dp[mask][u];
};
if (__builtin_popcount(mask) > 1) res += dp[mask][u];
};
};
cout << res;
};
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |