Submission #564743

# Submission time Handle Problem Language Result Execution time Memory
564743 2022-05-19T14:45:41 Z colossal_pepe Paths (BOI18_paths) C++17
100 / 100
659 ms 70800 KB
#include <iostream>
#include <vector>
using namespace std;

using ll = long long;

int n, m, k;
vector<int> c;
vector<vector<int>> g;

ll solve() {
    vector<vector<ll>> dp(n, vector<ll>((1 << k), 0));
    for (int u = 0; u < n; u++) {
        dp[u][(1 << c[u])] = 1;
    }
    ll ans = 0;
    for (int i = 2; i <= k; i++) {
        for (int u = 0; u < n; u++) {
            for (int v : g[u]) {
                if (c[u] == c[v]) continue;
                for (int mask = 0; mask < (1 << k); mask++) {
                    if (__builtin_popcount(mask) == i and mask&(1 << c[u]) and mask&(1 << c[v])) {
                        ans += dp[v][mask - (1 << c[u])];
                        dp[u][mask] += dp[v][mask - (1 << c[u])];
                    }
                }
            }
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> k;
    c.resize(n), g.resize(n);
    for (int u = 0; u < n; u++) {
        cin >> c[u];
        c[u]--;
    }
    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 time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 7052 KB Output is correct
2 Correct 67 ms 6212 KB Output is correct
3 Correct 367 ms 51792 KB Output is correct
4 Correct 88 ms 10588 KB Output is correct
5 Correct 103 ms 10096 KB Output is correct
6 Correct 330 ms 37336 KB Output is correct
7 Correct 371 ms 51900 KB Output is correct
8 Correct 448 ms 52696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 88 ms 7052 KB Output is correct
12 Correct 67 ms 6212 KB Output is correct
13 Correct 367 ms 51792 KB Output is correct
14 Correct 88 ms 10588 KB Output is correct
15 Correct 103 ms 10096 KB Output is correct
16 Correct 330 ms 37336 KB Output is correct
17 Correct 371 ms 51900 KB Output is correct
18 Correct 448 ms 52696 KB Output is correct
19 Correct 90 ms 6964 KB Output is correct
20 Correct 74 ms 6216 KB Output is correct
21 Correct 405 ms 51904 KB Output is correct
22 Correct 124 ms 10572 KB Output is correct
23 Correct 76 ms 10060 KB Output is correct
24 Correct 270 ms 37344 KB Output is correct
25 Correct 361 ms 51916 KB Output is correct
26 Correct 390 ms 52560 KB Output is correct
27 Correct 177 ms 6088 KB Output is correct
28 Correct 148 ms 8872 KB Output is correct
29 Correct 590 ms 70692 KB Output is correct
30 Correct 481 ms 39056 KB Output is correct
31 Correct 493 ms 38988 KB Output is correct
32 Correct 659 ms 70800 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 89 ms 2196 KB Output is correct
3 Correct 22 ms 2132 KB Output is correct
4 Correct 93 ms 17480 KB Output is correct
5 Correct 72 ms 17988 KB Output is correct
6 Correct 264 ms 36148 KB Output is correct
7 Correct 40 ms 2168 KB Output is correct
8 Correct 180 ms 23624 KB Output is correct
9 Correct 147 ms 24380 KB Output is correct
10 Correct 163 ms 24120 KB Output is correct
11 Correct 163 ms 19132 KB Output is correct
12 Correct 266 ms 28100 KB Output is correct
13 Correct 171 ms 19240 KB Output is correct
14 Correct 253 ms 36268 KB Output is correct
15 Correct 253 ms 36180 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct