답안 #572235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572235 2022-06-04T03:05:43 Z hoanghq2004 Paths (BOI18_paths) C++14
100 / 100
347 ms 59612 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, k;
int c[300010];
int f[300010][1 << 5];
vector <int> adj[300010];
long long res;

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> c[i];
        --c[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 mask = 1; mask < (1 << k); ++mask) {
        if (__builtin_popcount(mask) == 1) {
            int cl = __builtin_ctz(mask);
            for (int u = 1; u <= n; ++u)
                if (cl == c[u]) f[u][mask] = 1;
        } else {
            for (int u = 1; u <= n; ++u) {
                if (!((mask >> c[u]) & 1)) continue;
                for (auto v: adj[u]) {
                    if (c[u] == c[v]) continue;
                    f[u][mask] += f[v][mask ^ (1 << c[u])];
                }
            }
        }
    }
    for (int mask = 1; mask < (1 << k); ++mask) {
        if (__builtin_popcount(mask) == 1) continue;
        for (int u = 1; u <= n; ++u) res += f[u][mask];
    }
    cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 5 ms 7380 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 14384 KB Output is correct
2 Correct 53 ms 13228 KB Output is correct
3 Correct 294 ms 58852 KB Output is correct
4 Correct 102 ms 19000 KB Output is correct
5 Correct 78 ms 18944 KB Output is correct
6 Correct 180 ms 44328 KB Output is correct
7 Correct 286 ms 58952 KB Output is correct
8 Correct 230 ms 59612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 5 ms 7380 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7376 KB Output is correct
11 Correct 64 ms 14384 KB Output is correct
12 Correct 53 ms 13228 KB Output is correct
13 Correct 294 ms 58852 KB Output is correct
14 Correct 102 ms 19000 KB Output is correct
15 Correct 78 ms 18944 KB Output is correct
16 Correct 180 ms 44328 KB Output is correct
17 Correct 286 ms 58952 KB Output is correct
18 Correct 230 ms 59612 KB Output is correct
19 Correct 65 ms 14492 KB Output is correct
20 Correct 62 ms 13260 KB Output is correct
21 Correct 243 ms 58876 KB Output is correct
22 Correct 101 ms 18976 KB Output is correct
23 Correct 115 ms 19016 KB Output is correct
24 Correct 178 ms 44420 KB Output is correct
25 Correct 245 ms 58928 KB Output is correct
26 Correct 272 ms 59520 KB Output is correct
27 Correct 62 ms 13388 KB Output is correct
28 Correct 100 ms 15724 KB Output is correct
29 Correct 339 ms 58936 KB Output is correct
30 Correct 245 ms 36564 KB Output is correct
31 Correct 215 ms 36584 KB Output is correct
32 Correct 347 ms 58948 KB Output is correct
33 Correct 5 ms 7316 KB Output is correct
34 Correct 4 ms 7380 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 3 ms 7380 KB Output is correct
37 Correct 4 ms 7380 KB Output is correct
38 Correct 4 ms 7380 KB Output is correct
39 Correct 5 ms 7312 KB Output is correct
40 Correct 4 ms 7380 KB Output is correct
41 Correct 4 ms 7380 KB Output is correct
42 Correct 4 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7368 KB Output is correct
2 Correct 28 ms 9300 KB Output is correct
3 Correct 21 ms 9244 KB Output is correct
4 Correct 61 ms 24364 KB Output is correct
5 Correct 52 ms 25128 KB Output is correct
6 Correct 138 ms 24432 KB Output is correct
7 Correct 22 ms 9300 KB Output is correct
8 Correct 95 ms 24348 KB Output is correct
9 Correct 89 ms 25064 KB Output is correct
10 Correct 75 ms 25028 KB Output is correct
11 Correct 72 ms 16692 KB Output is correct
12 Correct 78 ms 21116 KB Output is correct
13 Correct 98 ms 16840 KB Output is correct
14 Correct 139 ms 24432 KB Output is correct
15 Correct 131 ms 24524 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7376 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 3 ms 7380 KB Output is correct