# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
719298 | Joshi503 | Race (IOI11_race) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define f first
#define s second
using vi = vector<int>;
using vpi = vector<pi>;
#define pb push_back
#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 rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
int test;
/*
*/
int n, k;
vi d;
vector<vpi> adj;
int mini;
void dfs(int u, int p, int len = 1){
each(v, adj[u]){
if(v.f == p) continue;
d[v.f] = d[u] + v.s;
if(d[v.f] == k){
mini = min(mini, len);
}
dfs(v.f, u, len + 1);
}
}
int best_path(int N, int K, int H[][2], int L[]){
adj = vector<vpi>(N + 1);
n = N, k = K;
F0R(i, N - 1){
int u = H[i][0], v = H[i][1];
adj[u].pb({v, L[i]});
adj[v].pb({u, L[i]});
}
int ans = 1e18;
F0R(i, N){
mini = 1e18;
d = vi(N + 1, 0LL);
dfs(i, -1);
ans = min(mini, ans);
}
return (ans == 1e18 ? -1 : ans);
}