Submission #1093368

#TimeUsernameProblemLanguageResultExecution timeMemory
1093368asli_bgRace (IOI11_race)C++11
0 / 100
6 ms12120 KiB
#pragma GCC optimize("O3,unroll-loops") #include "race.h" #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> inset; //#define int long long #define fi first #define se second #define all(x) x.begin(),x.end() #define pb push_back #define FOR(i,a) for(int i=0;i<(a);i++) #define FORE(i,a,b) for(int i=(a);i<(b);i++) #define cont(x) {for(auto el:x) cout<<el<<' ';cout<<endl;} #define contp(x) {for(auto el:x) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;} #define sp <<" "<< #define mid (l+r)/2 #define endl '\n' #define DEBUG(X) {cout<<#X<<' '<<(X)<<endl;} #define carp(x,y) ((x%MOD)*(y%MOD))%MOD #define topla(x,y) ((x%MOD)+(y%MOD))%MOD typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<bool> vb; const int MAXN=5e5+5; const int INF=1e9+7; const int MOD=1e9+7; vii adj[MAXN]; int n,k; int res; void merge(set<pii>& a,set<pii>& b, int cost){ if(a.size()<b.size()) swap(a,b); //setteki elemanlar--> {dist,edge sayisi} //adjdeki elemanlar--> {kom,dist} for(auto el:b){ el.fi+=cost; if(k-el.fi<0) break; auto it=a.lower_bound({k-el.fi,0}); int bir=(*it).fi; int iki=(*it).se; if(bir==k-el.fi){ res=min(res,iki+el.se+1+(bir!=0)); } } for(auto el:b) a.insert({el.fi+cost,el.se+1}); } set<pii> dfs(int nd,int ata){ set<pii> s; if(adj[nd].size()<=1 and nd!=1){ s.insert({0,0}); return s; } for(auto el:adj[nd]){ int kom=el.fi; int cost=el.se; if(kom!=ata){ auto c=dfs(kom,nd); merge(s,c,cost); } } return s; } int best_path(int N, int K, int H[][2], int L[]){ res=INF; k=K; n=N; FOR(i,n-1){ adj[H[i][0]].pb({H[i][1],L[i]}); adj[H[i][1]].pb({H[i][0],L[i]}); } dfs(1,0); if(res==INF) res=-1; return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...