제출 #531544

#제출 시각아이디문제언어결과실행 시간메모리
531544Killer2501Parkovi (COCI22_parkovi)C++14
110 / 110
1394 ms37700 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; else a[u] = -1; } bool check(ll x) { fill_n(vis, n+1, false); m = x; tong = 0; dfs(1); if(a[1] == -1) { vis[1] = true; ++tong; } return tong <= k; } 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; if(check(mid))r = mid-1; else l = mid+1; } check(l); 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 */

컴파일 시 표준 에러 (stderr) 메시지

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