제출 #712627

#제출 시각아이디문제언어결과실행 시간메모리
712627Urvuk3경주 (Race) (IOI11_race)C++17
0 / 100
30 ms340 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; #define ll long long const int INF=1e9; const ll LINF=1e18; #define fi first #define se second #define pii pair<int,int> #define mid ((l+r)/2) #define sz(a) (int((a).size())) #define all(a) a.begin(),a.end() #define endl "\n" #define pb push_back void PRINT(int x) {cerr << x;} void PRINT(ll x) {cerr << x;} void PRINT(double x) {cerr << x;} void PRINT(char x) {cerr << '\'' << x << '\'';} void PRINT(string x) {cerr << '\"' << x << '\"';} void PRINT(bool x) {cerr << (x ? "true" : "false");} template<typename T,typename V> void PRINT(pair<T,V>& x){ cerr<<"{"; PRINT(x.fi); cerr<<","; PRINT(x.se); cerr<<"}"; } template<typename T> void PRINT(T &x){ int id=0; cerr<<"{"; for(auto _i:x){ cerr<<(id++ ? "," : ""); PRINT(_i); } cerr<<"}"; } void _PRINT(){ cerr<<"]\n"; } template<typename Head,typename... Tail> void _PRINT(Head h,Tail... t){ PRINT(h); if(sizeof...(t)) cerr<<", "; _PRINT(t...); } #ifndef ONLINE_JUDGE #define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x) #endif vector<vector<pii>> adj; vector<bool> vis; vector<int> siz; vector<int> dub,dubw; unordered_map<int,int> global,local; int grana,W,res,T,H; void DfsDecompose(int node,int par){ siz[node]=1; for(pii e:adj[node]){ int v=e.fi; if(!vis[v] && v!=par){ DfsDecompose(v,node); siz[node]+=siz[v]; } } } void Dfs(int node,int par,int w){ if(par==-1){ dub[node]=1; dubw[node]=0; } else{ dub[node]=dub[par]+1; dubw[node]=dubw[par]+w; } T=dubw[node]+grana,H=dub[node]; Debug(node,T,H); local[T]=min((local.count(T) ? local[T] : INF),H); global[T]=min((global.count(T) ? global[T] : INF),H+1); res=min(res,local[T]+(global.count(W-T) ? global[W-T] : INF)); for(pii e:adj[node]){ if(!vis[e.fi] && e.fi!=par){ Dfs(e.fi,node,e.se); } } } int Find(int node,int par,int n){ for(pii e:adj[node]){ if(!vis[e.fi] && e.fi!=par && siz[e.fi]>n/2){ return Find(e.fi,node,n); } } return node; } int Find(int node){ DfsDecompose(node,-1); node=Find(node,-1,siz[node]); vis[node]=true; return node; } void Decompose(int node){ node=Find(node); Debug(node); global.clear(); for(pii e:adj[node]){ local.clear(); grana=e.se; Dfs(e.fi,-1,0); Debug(global,local); } for(pii e:adj[node]){ if(!vis[e.fi]) Decompose(e.fi); } } int best_path(int N, int K, int H[][2], int L[]){ Debug(N,K); adj.resize(N+1); siz.resize(N+1); vis.resize(N+1); dub.resize(N+1); dubw.resize(N+1); W=K; for(int i=0;i<N;i++){ int u=H[i][0]+1,v=H[i][1]+1,w=L[i]; adj[u].pb({v,w}); adj[v].pb({u,w}); } res=INF; Decompose(1); return (res==INF ? -1 : 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...