Submission #703836

#TimeUsernameProblemLanguageResultExecution timeMemory
703836Chal1shkanParkovi (COCI22_parkovi)C++14
10 / 110
325 ms14196 KiB
# include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define sz(x) ((int)(x).size()) # define deb(x) cerr << #x << " = " << x << endl; # define pll pair <ll, ll> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 2e5 + 25; const ll inf = 1e18 + 0; const ll mod = 1e9 + 7; const ll dx[] = {-1, 1, 0, 0}; const ll dy[] = {0, 0, -1, 1}; using namespace std; ll n, k, mx; vector <pll> g[maxn]; ll dist[maxn]; void dijkstra (int st) { dist[st] = 0; set <pair <ll, ll> > q; q.insert({0LL, st}); while (!q.empty()) { ll v = q.begin() -> ss; q.erase(q.begin()); for (auto i : g[v]) { ll to = i.ff, w = i.ss; if (dist[to] > dist[v] + w) { q.erase({dist[to], to}); dist[to] = dist[v] + w; q.insert({dist[to], to}); } } } } void ma1n (/* SABR */) { cin >> n >> k; for (ll i = 1, u, v, w; i < n; ++i) { cin >> u >> v >> w; g[u].pb({v, w}); g[v].pb({u, w}); } if (n <= 20) { ll ans = inf, ans_mask = 0; for (ll mask = 0; mask < (1LL << n); ++mask) { if (__builtin_popcount(mask) == k) { for (ll i = 1; i <= n; ++i) { dist[i] = inf; } for (ll i = 0; i < n; ++i) { if (mask & (1LL << i)) { dijkstra(i + 1); } } mx = 0; for (ll i = 1; i <= n; ++i) { mx = max(mx, dist[i]); } if (mx < ans) { ans = mx; ans_mask = mask; } } } cout << ans << nl; for (ll i = 0; i < n; ++i) { if (ans_mask & (1LL << i)) { cout << i + 1 << ' '; } } cout << nl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); int ttt = 1; // cin >> ttt; for (int test = 1; test <= ttt; ++test) { // cout << "Case " << test << ":" << ' '; ma1n(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...