#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#include "race.h"
const int maxn=1005;
vector<vector<pii>> adj(maxn);
vector<int> w(maxn),d(maxn),vis(maxn);
void dfs(int u,int p,int dep,int from){
if(vis[u]) return;
w[u]=p; d[u]=dep; vis[u]=1;
for(auto&v:adj[u]){
if(!vis[v.fi]&& v.fi!=from)
dfs(v.fi,p+v.se,dep+1,u);
}
}
int best_path(int n, int k, int H[][2], int L[])
{
for(int i=0;i<n-1;i++){
adj[H[i][0]].pb(mp(H[i][1],L[i]));
adj[H[i][1]].pb(mp(H[i][0],L[i]));
}
int ans=INT_MAX;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
d[j]=-1;
w[j]=-1;
vis[j]=0;
}
dfs(i,0,0,i);
for(int j=0;j<n;j++){
if(w[j]==k) ans=min(ans,d[j]);
}
}
if(ans==INT_MAX) return -1;
else return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
19 ms |
340 KB |
Output is correct |
22 |
Correct |
20 ms |
416 KB |
Output is correct |
23 |
Correct |
20 ms |
340 KB |
Output is correct |
24 |
Correct |
19 ms |
352 KB |
Output is correct |
25 |
Correct |
19 ms |
408 KB |
Output is correct |
26 |
Correct |
20 ms |
408 KB |
Output is correct |
27 |
Correct |
19 ms |
412 KB |
Output is correct |
28 |
Correct |
18 ms |
416 KB |
Output is correct |
29 |
Correct |
19 ms |
416 KB |
Output is correct |
30 |
Correct |
19 ms |
340 KB |
Output is correct |
31 |
Correct |
19 ms |
340 KB |
Output is correct |
32 |
Correct |
19 ms |
408 KB |
Output is correct |
33 |
Correct |
20 ms |
340 KB |
Output is correct |
34 |
Correct |
16 ms |
420 KB |
Output is correct |
35 |
Correct |
13 ms |
420 KB |
Output is correct |
36 |
Correct |
11 ms |
352 KB |
Output is correct |
37 |
Correct |
12 ms |
416 KB |
Output is correct |
38 |
Correct |
14 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Runtime error |
28 ms |
4356 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
19 ms |
340 KB |
Output is correct |
22 |
Correct |
20 ms |
416 KB |
Output is correct |
23 |
Correct |
20 ms |
340 KB |
Output is correct |
24 |
Correct |
19 ms |
352 KB |
Output is correct |
25 |
Correct |
19 ms |
408 KB |
Output is correct |
26 |
Correct |
20 ms |
408 KB |
Output is correct |
27 |
Correct |
19 ms |
412 KB |
Output is correct |
28 |
Correct |
18 ms |
416 KB |
Output is correct |
29 |
Correct |
19 ms |
416 KB |
Output is correct |
30 |
Correct |
19 ms |
340 KB |
Output is correct |
31 |
Correct |
19 ms |
340 KB |
Output is correct |
32 |
Correct |
19 ms |
408 KB |
Output is correct |
33 |
Correct |
20 ms |
340 KB |
Output is correct |
34 |
Correct |
16 ms |
420 KB |
Output is correct |
35 |
Correct |
13 ms |
420 KB |
Output is correct |
36 |
Correct |
11 ms |
352 KB |
Output is correct |
37 |
Correct |
12 ms |
416 KB |
Output is correct |
38 |
Correct |
14 ms |
404 KB |
Output is correct |
39 |
Runtime error |
28 ms |
4356 KB |
Execution killed with signal 6 |
40 |
Halted |
0 ms |
0 KB |
- |