Submission #783627

#TimeUsernameProblemLanguageResultExecution timeMemory
783627cig32Parkovi (COCI22_parkovi)C++17
0 / 110
118 ms42976 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int MAXN = 1e6 + 10; const int MOD = 998244353; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } vector<pair<int,int>> adj[MAXN]; int n, k, d[MAXN]; pair<int, vector<int> > find(int radius) { int used=0; vector<int> moments; for(int i=1;i<=n;i++){ int j=i; int bruh = 0; while(j+1 <= n && bruh + d[j] <= radius) { bruh += d[j]; j++; } bruh = 0; moments.push_back(j); while(j+1 <= n && bruh + d[j] <= radius) { bruh += d[j]; j++; } used++; i = j; } return {used, moments}; } void solve(int tc){ cin>>n>>k; for(int i=1;i<n;i++){ int a,b,w; cin>>a>>b>>w; d[i]=w; adj[a].push_back({b,w}); adj[b].push_back({a,w}); } int lb=1, rb=1e18; while(lb<rb){ int mid=(lb+rb)>>1; if(find(mid).first<=k) rb=mid; else lb=mid+1; } pair<int,vector<int>>res=find(lb); cout<<lb<<"\n"; for(int x:res.second)cout<<x<<" "; cout<<"\n"; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); } // 勿忘初衷
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...