# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384035 | MODDI | 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>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
#define MAX_N 500000
using namespace std;
vector<pii> G[200000];
static int N, K;
static int H[MAX_N][2];
static int L[MAX_N];
static int solution;
ll min(ll a, ll b){
if(a > b)
return b;
return a;
}
int best = 1e9;
void rec(int node, int cnt_nodes, int path, int parent){
if(path == K){
best = min(best, cnt_nodes);
return;
}
if(cnt_nodes >= best || path > K)
return;
for(auto next : G[node]){
if(next.first != parent){
rec(next.first, cnt_nodes + 1, path + next.second, node);
}
}
}
int best_path(int n, int k, int h[][2], int l[])
{
for(int i = 0; i < n-1; i++){
G[h[i][0]].pb(mp(h[i][1], l[i]));
G[h[i][1]].pb(mp(h[i][0], l[i]));
}
for(int i = 0; i < n; i++)
rec(i, 0, 0, -1);
if(best == 1e9)
return -1;
return best;
}
void read_input()
{
int i;
scanf("%d %d",&N,&K);
for(i=0; i<N-1; i++)
scanf("%d %d %d",&H[i][0],&H[i][1],&L[i]);
scanf("%d",&solution);
}
int main()
{
int ans;
read_input();
ans = best_path(N,K,H,L);
if(ans==solution)
printf("Correct.\n");
else
printf("Incorrect. Returned %d, Expected %d.\n",ans,solution);
return 0;
}