Submission #531539

#TimeUsernameProblemLanguageResultExecution timeMemory
531539Killer2501Parkovi (COCI22_parkovi)C++14
0 / 110
344 ms32840 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<ll, int> #define fi first #define se second using namespace std; const int N = 2e5+5; const int M = 250; const int mod = 1e9+7; const ll base = 75; const ll inf = 1e16; int n, lab[N], tong, d[N], t, c[N], dp[N], k; ll ans, m, a[N], b[N]; vector<pii> adj[N]; vector<pll> vi; string s; bool vis[N]; void dfs(int u, int p = 0) { b[u] = 0; a[u] = -1; for(pii v: adj[u]) { if(v.se == p)continue; dfs(v.se, u); if(a[v.se] != -1)a[u] = max(a[u], a[v.se]-v.fi); else { if(b[v.se]+v.fi > m) { ++tong; vis[v.se] = 1; a[u] = max(a[u], m-v.fi); } else b[u] = max(b[u], b[v.se]+v.fi); } } if(a[u] >= b[u])b[u] = 0; } void sol() { cin >> n >> k; for(int i = 1; i < n; i ++) { int x, y, w; cin >> x >> y >> w; adj[x].pb({w, y}); adj[y].pb({w, x}); } ll l = 0, r = 1e15, mid; while(l <= r) { mid = (l+r)>>1; m = mid; fill_n(vis, n+1, false); tong = 0; dfs(1); if(tong <= k)r = mid-1; else l = mid+1; } tong = 0; fill_n(vis, n+1, false); m = l; dfs(1); cout << l << '\n'; for(int i = 1; i <= n; i ++) { if(vis[i])cout << i <<" "; else if(tong < k) { ++tong; cout << i <<" "; } } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; while(test -- > 0)sol(); return 0; } /* 1234 21 */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         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...