제출 #412508

#제출 시각아이디문제언어결과실행 시간메모리
412508jeqcho경주 (Race) (IOI11_race)C++17
9 / 100
531 ms262148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second struct triple{ int a,b,c; }; int const n=2e5; vpi adj[n]; int const INF=1e9; int mn=INF; int k; vi dfs(int now, int par) { vector<triple> cur(k+1); F0R(i,k+1) { cur[i]={INF,-1,-1}; } cur[0].a=0; cur[0].b=now; trav(chi,adj[now]) { if(chi.fi==par)continue; vi res = dfs(chi.fi,now); F0R(i,k+1) { if(i-chi.se<0)continue; if(res[i-chi.se]+1 == cur[i].a) { cur[i].c=chi.fi; } else if(res[i-chi.se]+1 < cur[i].a) { cur[i] = {res[i-chi.se]+1, chi.fi,-1}; } } } adj[now].clear(); F0R(i,k+1) { if(cur[i].a==-1)continue; if(cur[k-i].a==-1)continue; if(cur[i].b==cur[k-i].b) { if(cur[i].c==-1&&cur[k-i].c==-1)continue; } mn=min(mn,cur[i].a+cur[k-i].a); } vi nxt(k+1); F0R(i,k+1) { nxt[i]=cur[i].a; } return nxt; } int best_path(int N, int K, int H[][2], int L[]){ k=K; F0R(i,N-1) { int u = H[i][0]; int v = H[i][1]; adj[u].pb({v,L[i]}); adj[v].pb({u,L[i]}); } dfs(0,-1); if(mn>=INF)return -1; return mn; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...