# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
872818 | 2023-11-13T21:11:36 Z | tvladm2009 | Paths (BOI18_paths) | C++17 | 357 ms | 110244 KB |
#include <bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2,fma") #define sz(x) (x).size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using db = long double; // or double, if TL is tight using str = string; using ii = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; struct tree { const int SIGMA = 5; int n; vector<vector<int>> L; vector<int> Cul; vector<vector<int64_t>> DP; tree(int N, vector<int> c) : n(N), L(N), DP(N + 1, vector<int64_t>(1 << SIGMA, 0)), Cul(c) {} void add_edge(int x, int y) { L[x].push_back(y); L[y].push_back(x); } int64_t solve(int k) { // for(int i = 0; i < n; i++) // cout << Cul[i] << " "; // cout << "\n"; int64_t res = 0; for(int mask = 1; mask < (1 << k); ++mask) { for(int i = 0; i < n; ++i) { if(mask & (1 << Cul[i])) { if(mask ^ (1 << Cul[i])) for(auto v : L[i]) DP[i][mask] += DP[v][mask ^ (1 << Cul[i])]; else DP[i][mask] = 1; } res += DP[i][mask]; } } return res; } }; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; vector<int> c(n); for(int i = 0; i < n; ++i) { cin >> c[i]; --c[i]; } tree T(n, c); for(int i = 0; i < m; ++i) { int x, y; cin >> x >> y; --x; --y; T.add_edge(x, y); } cout << T.solve(k) - n << "\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 460 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 8304 KB | Output is correct |
2 | Correct | 41 ms | 6564 KB | Output is correct |
3 | Correct | 246 ms | 109496 KB | Output is correct |
4 | Correct | 64 ms | 17776 KB | Output is correct |
5 | Correct | 60 ms | 17664 KB | Output is correct |
6 | Correct | 233 ms | 75844 KB | Output is correct |
7 | Correct | 242 ms | 109504 KB | Output is correct |
8 | Correct | 243 ms | 110012 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 460 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 44 ms | 8304 KB | Output is correct |
12 | Correct | 41 ms | 6564 KB | Output is correct |
13 | Correct | 246 ms | 109496 KB | Output is correct |
14 | Correct | 64 ms | 17776 KB | Output is correct |
15 | Correct | 60 ms | 17664 KB | Output is correct |
16 | Correct | 233 ms | 75844 KB | Output is correct |
17 | Correct | 242 ms | 109504 KB | Output is correct |
18 | Correct | 243 ms | 110012 KB | Output is correct |
19 | Correct | 44 ms | 8480 KB | Output is correct |
20 | Correct | 33 ms | 6476 KB | Output is correct |
21 | Correct | 265 ms | 109592 KB | Output is correct |
22 | Correct | 69 ms | 17748 KB | Output is correct |
23 | Correct | 83 ms | 17716 KB | Output is correct |
24 | Correct | 161 ms | 75736 KB | Output is correct |
25 | Correct | 232 ms | 109380 KB | Output is correct |
26 | Correct | 305 ms | 110244 KB | Output is correct |
27 | Correct | 35 ms | 6492 KB | Output is correct |
28 | Correct | 56 ms | 10120 KB | Output is correct |
29 | Correct | 357 ms | 109504 KB | Output is correct |
30 | Correct | 200 ms | 58632 KB | Output is correct |
31 | Correct | 202 ms | 58464 KB | Output is correct |
32 | Correct | 356 ms | 109504 KB | Output is correct |
33 | Correct | 0 ms | 344 KB | Output is correct |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 0 ms | 344 KB | Output is correct |
37 | Correct | 0 ms | 344 KB | Output is correct |
38 | Correct | 0 ms | 348 KB | Output is correct |
39 | Correct | 0 ms | 348 KB | Output is correct |
40 | Correct | 0 ms | 348 KB | Output is correct |
41 | Correct | 0 ms | 452 KB | Output is correct |
42 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Correct | 14 ms | 2396 KB | Output is correct |
3 | Correct | 11 ms | 2396 KB | Output is correct |
4 | Correct | 59 ms | 36564 KB | Output is correct |
5 | Correct | 57 ms | 37436 KB | Output is correct |
6 | Correct | 134 ms | 36552 KB | Output is correct |
7 | Correct | 13 ms | 2396 KB | Output is correct |
8 | Correct | 111 ms | 36872 KB | Output is correct |
9 | Correct | 86 ms | 37428 KB | Output is correct |
10 | Correct | 79 ms | 37324 KB | Output is correct |
11 | Correct | 58 ms | 19300 KB | Output is correct |
12 | Correct | 81 ms | 28592 KB | Output is correct |
13 | Correct | 65 ms | 19856 KB | Output is correct |
14 | Correct | 144 ms | 36556 KB | Output is correct |
15 | Correct | 141 ms | 36552 KB | Output is correct |
16 | Correct | 0 ms | 344 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 476 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 348 KB | Output is correct |
23 | Correct | 0 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 0 ms | 348 KB | Output is correct |