# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056222 | 2024-08-13T08:19:06 Z | manhlinh1501 | Parkovi (COCI22_parkovi) | C++17 | 36 ms | 15444 KB |
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using i64 = long long; using pli = pair<i64, int>; const int MAXN = 2e5 + 5; const i64 oo64 = 1e18; #define ALL(a) (a).begin(), (a).end() int N, K; vector<pii> adj[MAXN]; namespace subtask { const int MAXN = 25; bool is_subtask() { return N <= 20; } i64 dist[MAXN][MAXN]; void DFS(int r, int u, int p) { for(auto [v, w] : adj[u]) { if(v == p) continue; dist[r][v] = dist[r][u] + w; DFS(r, v, u); } } void solution() { if(is_subtask() == false) return; for(int i = 1; i <= N; i++) { dist[i][i] = 0; DFS(i, i, 0); } i64 ans = oo64; int best = 0; for(int mask = 0; mask < (1 << N); mask++) { if(__builtin_popcount(mask) != K) continue; vector<int> b(N + 1, 0); for(int i = 0; i < N; i++) b[i + 1] = (mask >> i & 1); i64 res = 0; for(int i = 1; i <= N; i++) { i64 minn = oo64; for(int j = 1; j <= N; j++) { if(b[j]) minn = min(minn, dist[i][j]); } res = max(res, minn); } if(ans > res) { ans = res; best = mask; } } cout << ans; cout << "\n"; for(int i = 0; i < N; i++) { if(best >> i & 1) cout << i + 1 << " "; } exit(0); } } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K; for(int i = 1; i < N; i++) { int u, v, w; cin >> u >> v >> w; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } subtask::solution(); return (0 ^ 0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4956 KB | Output is correct |
2 | Correct | 3 ms | 4956 KB | Output is correct |
3 | Correct | 3 ms | 4956 KB | Output is correct |
4 | Correct | 3 ms | 4956 KB | Output is correct |
5 | Correct | 3 ms | 4956 KB | Output is correct |
6 | Correct | 8 ms | 5160 KB | Output is correct |
7 | Correct | 8 ms | 4956 KB | Output is correct |
8 | Correct | 4 ms | 4956 KB | Output is correct |
9 | Correct | 32 ms | 4956 KB | Output is correct |
10 | Correct | 5 ms | 4956 KB | Output is correct |
11 | Correct | 16 ms | 4956 KB | Output is correct |
12 | Correct | 29 ms | 4956 KB | Output is correct |
13 | Correct | 3 ms | 4956 KB | Output is correct |
14 | Correct | 15 ms | 5156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 33 ms | 13604 KB | Unexpected end of file - int64 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 36 ms | 15444 KB | Unexpected end of file - int64 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4956 KB | Output is correct |
2 | Correct | 3 ms | 4956 KB | Output is correct |
3 | Correct | 3 ms | 4956 KB | Output is correct |
4 | Correct | 3 ms | 4956 KB | Output is correct |
5 | Correct | 3 ms | 4956 KB | Output is correct |
6 | Correct | 8 ms | 5160 KB | Output is correct |
7 | Correct | 8 ms | 4956 KB | Output is correct |
8 | Correct | 4 ms | 4956 KB | Output is correct |
9 | Correct | 32 ms | 4956 KB | Output is correct |
10 | Correct | 5 ms | 4956 KB | Output is correct |
11 | Correct | 16 ms | 4956 KB | Output is correct |
12 | Correct | 29 ms | 4956 KB | Output is correct |
13 | Correct | 3 ms | 4956 KB | Output is correct |
14 | Correct | 15 ms | 5156 KB | Output is correct |
15 | Incorrect | 33 ms | 13604 KB | Unexpected end of file - int64 expected |
16 | Halted | 0 ms | 0 KB | - |