Submission #1015759

# Submission time Handle Problem Language Result Execution time Memory
1015759 2024-07-06T18:06:26 Z phoenix Paths (BOI18_paths) C++17
100 / 100
313 ms 70736 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 300100;

int n, m, k;
vector<int> g[N];
int color[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> color[i];
        color[i]--;
    }
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> ord((1 << k) - 1);
    iota(ord.begin(), ord.end(), 1);
    sort(ord.begin(), ord.end(), [&](int a, int b) {
        return __builtin_popcount(a) <= __builtin_popcount(b);
    });

    vector<vector<long long>> dp(n + 1, vector<long long>(1 << k));
    for (int i = 1; i <= n; i++) {
        dp[i][(1 << color[i])] = 1;
    }
    for (int msk : ord) {
        for (int v = 1; v <= n; v++) {
            for (int to : g[v]) {
                if (msk >> color[to] & 1) continue;
                dp[to][msk | (1 << color[to])] += dp[v][msk];
            }
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int msk = 1; msk < (1 << k); msk++) {
            if (__builtin_popcount(msk) < 2) continue;
            ans += dp[i][msk];
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 1 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 1 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 1 ms 8284 KB Output is correct
10 Correct 1 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 12116 KB Output is correct
2 Correct 37 ms 11868 KB Output is correct
3 Correct 174 ms 51284 KB Output is correct
4 Correct 61 ms 17996 KB Output is correct
5 Correct 70 ms 17748 KB Output is correct
6 Correct 126 ms 40060 KB Output is correct
7 Correct 194 ms 51792 KB Output is correct
8 Correct 219 ms 52564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 1 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 1 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 1 ms 8284 KB Output is correct
10 Correct 1 ms 8284 KB Output is correct
11 Correct 57 ms 12116 KB Output is correct
12 Correct 37 ms 11868 KB Output is correct
13 Correct 174 ms 51284 KB Output is correct
14 Correct 61 ms 17996 KB Output is correct
15 Correct 70 ms 17748 KB Output is correct
16 Correct 126 ms 40060 KB Output is correct
17 Correct 194 ms 51792 KB Output is correct
18 Correct 219 ms 52564 KB Output is correct
19 Correct 54 ms 14940 KB Output is correct
20 Correct 44 ms 14316 KB Output is correct
21 Correct 200 ms 52052 KB Output is correct
22 Correct 67 ms 18000 KB Output is correct
23 Correct 60 ms 17544 KB Output is correct
24 Correct 116 ms 40132 KB Output is correct
25 Correct 192 ms 51796 KB Output is correct
26 Correct 181 ms 52564 KB Output is correct
27 Correct 66 ms 14172 KB Output is correct
28 Correct 82 ms 16772 KB Output is correct
29 Correct 313 ms 70608 KB Output is correct
30 Correct 174 ms 43204 KB Output is correct
31 Correct 173 ms 43208 KB Output is correct
32 Correct 298 ms 70736 KB Output is correct
33 Correct 2 ms 8280 KB Output is correct
34 Correct 2 ms 8532 KB Output is correct
35 Correct 2 ms 8284 KB Output is correct
36 Correct 2 ms 8280 KB Output is correct
37 Correct 2 ms 8284 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
39 Correct 2 ms 8284 KB Output is correct
40 Correct 2 ms 8284 KB Output is correct
41 Correct 2 ms 8284 KB Output is correct
42 Correct 2 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 31 ms 9660 KB Output is correct
3 Correct 14 ms 9564 KB Output is correct
4 Correct 47 ms 21596 KB Output is correct
5 Correct 33 ms 22216 KB Output is correct
6 Correct 114 ms 40284 KB Output is correct
7 Correct 21 ms 9564 KB Output is correct
8 Correct 67 ms 27888 KB Output is correct
9 Correct 46 ms 28628 KB Output is correct
10 Correct 61 ms 28496 KB Output is correct
11 Correct 83 ms 24780 KB Output is correct
12 Correct 76 ms 33108 KB Output is correct
13 Correct 81 ms 24916 KB Output is correct
14 Correct 120 ms 40272 KB Output is correct
15 Correct 130 ms 40516 KB Output is correct
16 Correct 2 ms 8280 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 2 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8280 KB Output is correct
24 Correct 2 ms 8284 KB Output is correct
25 Correct 2 ms 8284 KB Output is correct