Submission #1004621

#TimeUsernameProblemLanguageResultExecution timeMemory
1004621vjudge1Parkovi (COCI22_parkovi)C++17
110 / 110
1493 ms44488 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPD(i, n) for (int i = (n) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX 200005 struct Edge{ int u, v, w; Edge(){} Edge(int _u, int _v, int _w): u(_u), v(_v), w(_w){} int other(int x){return (x ^ u ^ v);} } edge[MAX]; int numNode, k; vector<int> G[MAX]; void loadGraph(void){ cin >> numNode >> k; for (int i = 1; i < numNode; ++i){ cin >> edge[i].u >> edge[i].v >> edge[i].w; G[edge[i].u].emplace_back(i); G[edge[i].v].emplace_back(i); } } int minDist[MAX], maxReach[MAX]; vector<int> candidate; void dfs(int u, int p, int d){ for (int &i : G[u]){ int v = edge[i].other(u); if(v ^ p){ dfs(v, u, d); if (maxReach[v] + min(edge[i].w, minDist[v]) <= d){ if (maxReach[v] + minDist[v] > d) maximize(maxReach[u], maxReach[v] + edge[i].w); minimize(minDist[u], minDist[v] + edge[i].w); } else{ candidate.emplace_back(v); minimize(minDist[u], edge[i].w); } } } } bool check(int d){ candidate.clear(); memset(maxReach, 0, (numNode + 1) * sizeof(int)); memset(minDist, 0x3f, (numNode + 1) * sizeof(int)); dfs(1, -1, d); if (maxReach[1] + minDist[1] > d) candidate.push_back(1); return (int)candidate.size() <= k; } int chosen[MAX]; void process(void){ int l = 0, r = 1e15; while(r - l > 1){ int m = (l + r) >> 1; if(check(m)) r = m; else l = m; } cout << r << '\n'; check(r); for (int& v : candidate) chosen[v] = 1; for (int i = 1; i <= numNode; ++i) { if(!chosen[i] && (int)candidate.size() < k) candidate.push_back(i); } for (int &v : candidate) cout << v << " "; } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); loadGraph(); process(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...