| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1287100 | wedonttalkanymore | Paths (BOI18_paths) | C++20 | 162 ms | 57576 KiB | 
#include <bits/stdc++.h>
/*
    Phia ben kia dai duong cung chi co
    Bo cat nang niu bien thoi
*/
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 6;
int n, m, k;
int a[N];
vector <int> adj[N];
int dp[N][1 << lim];
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen(".inp", "r")) {
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) dp[i][1 << a[i]] = 1;
    for (int mask = 1; mask < (1 << k); mask++) {
        for (int u = 1; u <= n; u++) {
            for (auto v : adj[u]) {
                if (!((mask >> a[v]) & 1)) {
                    dp[v][mask | (1 << a[v])] += dp[u][mask];
                }
            }
        }
    }
    int ans = 0;
    for (int mask = 1; mask < (1 << k); mask++) {
        for (int i = 1; i <= n; i++) {
            if (__builtin_popcount(mask) > 1) ans += dp[i][mask];
        }
    }
    cout << ans;
    return 0;
}
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... | ||||
