Submission #1056222

#TimeUsernameProblemLanguageResultExecution timeMemory
1056222manhlinh1501Parkovi (COCI22_parkovi)C++17
10 / 110
36 ms15444 KiB
#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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...