#include <bits/stdc++.h>
#include "race.h"
const int nmax=1e6+5;
using namespace std;
vector<pair<int,int> > h[nmax];
int sum,d;
int res=0x3f;
bool visted[nmax];
void dfs(int s,int k)
{
visted[s]=1;
if (sum==k)
{
res=min(res,d);
}
for (auto x : h[s])
{
if (!visted[x.first])
{
sum+=x.second;
d++;
dfs(x.first,k);
sum-=x.second;
d--;
}
}
}
int best_path(int N,int K,int H[][2],int L[])
{
for (int i=0;i<N-1;i++)
{
int a=H[i][0];
int b=H[i][1];
h[a].push_back({b,L[i]});
h[b].push_back({a,L[i]});
}
for (int i=1;i<=N;i++)
{
memset(visted,0,sizeof visted);
d=0;
sum=0;
dfs(i,K);
}
if (res==0x3f) res=-1;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
28508 KB |
Output is correct |
2 |
Correct |
7 ms |
28508 KB |
Output is correct |
3 |
Correct |
7 ms |
28508 KB |
Output is correct |
4 |
Correct |
7 ms |
28368 KB |
Output is correct |
5 |
Correct |
9 ms |
28304 KB |
Output is correct |
6 |
Correct |
7 ms |
28508 KB |
Output is correct |
7 |
Correct |
7 ms |
28380 KB |
Output is correct |
8 |
Correct |
8 ms |
28508 KB |
Output is correct |
9 |
Correct |
7 ms |
28372 KB |
Output is correct |
10 |
Correct |
7 ms |
28764 KB |
Output is correct |
11 |
Correct |
7 ms |
28508 KB |
Output is correct |
12 |
Correct |
7 ms |
28508 KB |
Output is correct |
13 |
Correct |
7 ms |
28356 KB |
Output is correct |
14 |
Correct |
8 ms |
28508 KB |
Output is correct |
15 |
Correct |
7 ms |
28548 KB |
Output is correct |
16 |
Correct |
7 ms |
28508 KB |
Output is correct |
17 |
Incorrect |
8 ms |
28540 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
28508 KB |
Output is correct |
2 |
Correct |
7 ms |
28508 KB |
Output is correct |
3 |
Correct |
7 ms |
28508 KB |
Output is correct |
4 |
Correct |
7 ms |
28368 KB |
Output is correct |
5 |
Correct |
9 ms |
28304 KB |
Output is correct |
6 |
Correct |
7 ms |
28508 KB |
Output is correct |
7 |
Correct |
7 ms |
28380 KB |
Output is correct |
8 |
Correct |
8 ms |
28508 KB |
Output is correct |
9 |
Correct |
7 ms |
28372 KB |
Output is correct |
10 |
Correct |
7 ms |
28764 KB |
Output is correct |
11 |
Correct |
7 ms |
28508 KB |
Output is correct |
12 |
Correct |
7 ms |
28508 KB |
Output is correct |
13 |
Correct |
7 ms |
28356 KB |
Output is correct |
14 |
Correct |
8 ms |
28508 KB |
Output is correct |
15 |
Correct |
7 ms |
28548 KB |
Output is correct |
16 |
Correct |
7 ms |
28508 KB |
Output is correct |
17 |
Incorrect |
8 ms |
28540 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
28508 KB |
Output is correct |
2 |
Correct |
7 ms |
28508 KB |
Output is correct |
3 |
Correct |
7 ms |
28508 KB |
Output is correct |
4 |
Correct |
7 ms |
28368 KB |
Output is correct |
5 |
Correct |
9 ms |
28304 KB |
Output is correct |
6 |
Correct |
7 ms |
28508 KB |
Output is correct |
7 |
Correct |
7 ms |
28380 KB |
Output is correct |
8 |
Correct |
8 ms |
28508 KB |
Output is correct |
9 |
Correct |
7 ms |
28372 KB |
Output is correct |
10 |
Correct |
7 ms |
28764 KB |
Output is correct |
11 |
Correct |
7 ms |
28508 KB |
Output is correct |
12 |
Correct |
7 ms |
28508 KB |
Output is correct |
13 |
Correct |
7 ms |
28356 KB |
Output is correct |
14 |
Correct |
8 ms |
28508 KB |
Output is correct |
15 |
Correct |
7 ms |
28548 KB |
Output is correct |
16 |
Correct |
7 ms |
28508 KB |
Output is correct |
17 |
Incorrect |
8 ms |
28540 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
28508 KB |
Output is correct |
2 |
Correct |
7 ms |
28508 KB |
Output is correct |
3 |
Correct |
7 ms |
28508 KB |
Output is correct |
4 |
Correct |
7 ms |
28368 KB |
Output is correct |
5 |
Correct |
9 ms |
28304 KB |
Output is correct |
6 |
Correct |
7 ms |
28508 KB |
Output is correct |
7 |
Correct |
7 ms |
28380 KB |
Output is correct |
8 |
Correct |
8 ms |
28508 KB |
Output is correct |
9 |
Correct |
7 ms |
28372 KB |
Output is correct |
10 |
Correct |
7 ms |
28764 KB |
Output is correct |
11 |
Correct |
7 ms |
28508 KB |
Output is correct |
12 |
Correct |
7 ms |
28508 KB |
Output is correct |
13 |
Correct |
7 ms |
28356 KB |
Output is correct |
14 |
Correct |
8 ms |
28508 KB |
Output is correct |
15 |
Correct |
7 ms |
28548 KB |
Output is correct |
16 |
Correct |
7 ms |
28508 KB |
Output is correct |
17 |
Incorrect |
8 ms |
28540 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |