Submission #397731

# Submission time Handle Problem Language Result Execution time Memory
397731 2021-05-03T01:18:37 Z KoD Paths (BOI18_paths) C++17
100 / 100
733 ms 70768 KB
#include <bits/stdc++.h>

using ll = long long;

template <class T>
using Vec = std::vector<T>;

int main() {
    int N, M, K;
    std::cin >> N >> M >> K;
    Vec<int> col(N);
    for (auto& x: col) {
        std::cin >> x;
        x -= 1;
    }
    Vec<Vec<int>> graph(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        std::cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    Vec<Vec<ll>> count(N, Vec<ll>(1 << K));
    for (int i = 0; i < N; ++i) {
        count[i][1 << col[i]] += 1;
    }
    for (int set = 0; set < (1 << K); ++set) {
        for (int i = 0; i < N; ++i) {
            if (!(set >> col[i] & 1)) {
                continue;
            }
            for (const auto j: graph[i]) {
                count[i][set] += count[j][set & ~(1 << col[i])];
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < (1 << K); ++j) {
            if (__builtin_popcount(j) >= 2) {
                ans += count[i][j];               
            }
        }
    }
    std::cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 6984 KB Output is correct
2 Correct 145 ms 6092 KB Output is correct
3 Correct 548 ms 51892 KB Output is correct
4 Correct 219 ms 10608 KB Output is correct
5 Correct 226 ms 10196 KB Output is correct
6 Correct 411 ms 37348 KB Output is correct
7 Correct 557 ms 51972 KB Output is correct
8 Correct 636 ms 52536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 179 ms 6984 KB Output is correct
12 Correct 145 ms 6092 KB Output is correct
13 Correct 548 ms 51892 KB Output is correct
14 Correct 219 ms 10608 KB Output is correct
15 Correct 226 ms 10196 KB Output is correct
16 Correct 411 ms 37348 KB Output is correct
17 Correct 557 ms 51972 KB Output is correct
18 Correct 636 ms 52536 KB Output is correct
19 Correct 172 ms 7012 KB Output is correct
20 Correct 143 ms 6212 KB Output is correct
21 Correct 558 ms 52080 KB Output is correct
22 Correct 222 ms 10584 KB Output is correct
23 Correct 224 ms 10044 KB Output is correct
24 Correct 428 ms 37396 KB Output is correct
25 Correct 562 ms 51936 KB Output is correct
26 Correct 576 ms 52544 KB Output is correct
27 Correct 146 ms 6084 KB Output is correct
28 Correct 197 ms 8644 KB Output is correct
29 Correct 732 ms 70768 KB Output is correct
30 Correct 504 ms 38904 KB Output is correct
31 Correct 525 ms 38852 KB Output is correct
32 Correct 733 ms 70732 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 53 ms 2132 KB Output is correct
3 Correct 47 ms 2124 KB Output is correct
4 Correct 156 ms 17300 KB Output is correct
5 Correct 132 ms 18200 KB Output is correct
6 Correct 336 ms 36260 KB Output is correct
7 Correct 49 ms 2116 KB Output is correct
8 Correct 210 ms 23588 KB Output is correct
9 Correct 163 ms 24352 KB Output is correct
10 Correct 186 ms 24124 KB Output is correct
11 Correct 166 ms 19100 KB Output is correct
12 Correct 176 ms 28092 KB Output is correct
13 Correct 182 ms 19112 KB Output is correct
14 Correct 297 ms 36036 KB Output is correct
15 Correct 305 ms 36220 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 292 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct