# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
719281 | 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
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
#define sz(x) ll((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define pb push_back
#define yes cout << "Y" << "e" << "s\n";
#define no cout << "N" << "o\n";
#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)
const int MOD = 998244353;
const int MOD98 = 998244353;
const int MX = 1e9;
const int INF = 1e18;
const db PI = acos((db)-1);
/*
*/
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);
}