Submission #1301280

#TimeUsernameProblemLanguageResultExecution timeMemory
1301280Faisal_SaqibParkovi (COCI22_parkovi)C++20
0 / 110
196 ms50652 KiB
/* VENI VIDI VICI */ // #ifdef ONLINE_JUDGE #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); using i128 = __int128; using ll = long long; using ull = unsigned long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pair<int, int>>; using vvi = vector<vi>; using sll = set<ll>; template<class T> istream& operator>>(istream& is, vector<T>& v) { for(auto &i:v) is>>i; return is; } template<class T1,class T2> istream& operator>>(istream& is, pair<T1,T2>& p) { is>>p.fi>>p.se; return is; } template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { for(const auto &i:v) os<<i<<' '; return os; } template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& p) { os<<p.fi<<' '<<p.se; return os; } void pyn(bool x) { cout<<(x?"YES":"NO")<<endl; } void pYN(bool x) { cout<<(x?"Yes":"No")<<endl; } void pAB(bool x) { cout<<(x?"Alice":"Bob")<<endl; } ll powmod(ll a,ll b,ll modulo) { if(b==0){ return 1; } ll temp=powmod(a,b/2,modulo); if(b%2==0){ return (temp*temp)%modulo; } else{ return (a*((temp*temp)%modulo))%modulo; } } bool Prime(ll n){ for (ll i = 2; i*i <= n; i++) if (n % i == 0) return false; return (n>1); } void readIO() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); } // #endif void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); readIO(); int uwu=1; // cin>>uwu; for(int tc=1;tc<=uwu;tc++) { // cout<<"Case #"<<tc<<": "; solve(); } return 0; } const int N=2e5+10; const ll inf=1e16; ll deg[N],rh[N],dp[N]; set<pair<ll,ll>> ma[N]; vector<vl> edg; void solve() { ll n,k; cin>>n>>k; for(int i=1;i<n;i++) { ll x,y,w; cin>>x>>y>>w; edg.push_back({x,y,w}); // ma[x].insert({y,w}); // ma[y].insert({x,w}); } ll s=-1,e=100+1; vector<int> pt; while(s+1<e) { ll mid=(s+e)/2; // ll mid=8; for(auto it:edg) { ll x=it[0],y=it[1],w=it[2]; ma[x].insert({y,w}); ma[y].insert({x,w}); } set<pair<ll,ll>> leaves; // cout<<"AT "<<mid<<endl; ll rem=n; for(int i=1;i<=n;i++) { deg[i]=ma[i].size(); rh[i]=inf; dp[i]=0; if(deg[i]==1) { leaves.insert({dp[i],i}); } } ll cnt=0; vector<int> anode; while(leaves.size()>0) { auto itp=*begin(leaves); ll x=itp.second; ll dd=dp[x]; leaves.erase(begin(leaves)); rem--; // cout<<"Vertex "<<x<<endl; // cout<<dd<<' '<<rh[x]<<' '<<mid<<' '<<x<<endl; // asopdapsdoi paoisdp oaispodi if(ma[x].size()==0) { if(dd+rh[x] <=mid) { } else{ // cout<<"Selected "<<x<<endl; cnt++; anode.push_back(x); } break; } // depend[x] = maximum distance to a node depended on node x // reach[x] = minimum distance to a node that was selected itp=*begin(ma[x]); ll y=itp.first,w=itp.second; leaves.erase({dp[y],y}); if(dd+rh[x] <= mid) { // all nodes covered } else if((dd+w)<=mid) { } else{ // we will have to select x // rh[y]=min(rh[y],w); rh[y]=0; dd=-w; cnt++; anode.push_back(x); } dp[y]=max(dp[y],dd+w); rh[y]=min(rh[y],rh[x]+w); itp.first=x; ma[y].erase(itp); if(ma[y].size()<=1) { leaves.insert({dp[y],y}); } } if(cnt<=k) { e=mid; pt=anode; } else{ s=mid; } } cout<<e<<endl; set<int> pts(all(pt)); for(int i=1;i<=n and pts.size()+1<=k;i++) { if(pts.find(i)==pts.end()) { pts.insert(i); } } for(auto x:pts)cout<<x<<' '; cout<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...