#include "race.h"
#include<bits/stdc++.h>
using namespace std ;
int n , k , dis[1001] ;
vector<pair<int , int >> adj[1001];
int vis[1001] , vid ;
int bfs(int s){
memset(dis , 0 , sizeof dis);
queue<pair<int , int > > q ;
q.push({s , 0});
dis[s] = 0 ; vis[s] = vid ;
while(!q.empty()){
auto f = q.front();
q.pop();
for(auto c : adj[f.first]){
if(vis[c.first] == vid)continue ;
int nc = f.second + c.second ;
int nd = dis[f.first] + 1 ;
dis[c.first] = nd ;
vis[c.first] = vid ;
q.push({c.first , nc});
if(nc == k)return nd ;
}
}
return 1e9 ;
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K ;
int mn = 1e9 ;
for(int i = 0 ; i < N ; i ++){
int from = H[i][0] , to = H[i][1];
adj[from].push_back({to , L[i]});
adj[to].push_back({from , L[i]});
}
for(int i = 0 ; i < N ; i ++)
vid ++ , mn = min(mn , bfs(i));
return (mn == 1e9 ? -1 : mn);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
24 ms |
332 KB |
Output is correct |
22 |
Correct |
22 ms |
332 KB |
Output is correct |
23 |
Correct |
22 ms |
332 KB |
Output is correct |
24 |
Correct |
21 ms |
408 KB |
Output is correct |
25 |
Correct |
22 ms |
332 KB |
Output is correct |
26 |
Correct |
22 ms |
332 KB |
Output is correct |
27 |
Correct |
21 ms |
412 KB |
Output is correct |
28 |
Correct |
21 ms |
400 KB |
Output is correct |
29 |
Correct |
21 ms |
460 KB |
Output is correct |
30 |
Correct |
25 ms |
412 KB |
Output is correct |
31 |
Correct |
25 ms |
332 KB |
Output is correct |
32 |
Correct |
21 ms |
332 KB |
Output is correct |
33 |
Correct |
26 ms |
332 KB |
Output is correct |
34 |
Correct |
21 ms |
400 KB |
Output is correct |
35 |
Correct |
16 ms |
332 KB |
Output is correct |
36 |
Correct |
14 ms |
332 KB |
Output is correct |
37 |
Correct |
13 ms |
332 KB |
Output is correct |
38 |
Correct |
17 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Runtime error |
38 ms |
2896 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
24 ms |
332 KB |
Output is correct |
22 |
Correct |
22 ms |
332 KB |
Output is correct |
23 |
Correct |
22 ms |
332 KB |
Output is correct |
24 |
Correct |
21 ms |
408 KB |
Output is correct |
25 |
Correct |
22 ms |
332 KB |
Output is correct |
26 |
Correct |
22 ms |
332 KB |
Output is correct |
27 |
Correct |
21 ms |
412 KB |
Output is correct |
28 |
Correct |
21 ms |
400 KB |
Output is correct |
29 |
Correct |
21 ms |
460 KB |
Output is correct |
30 |
Correct |
25 ms |
412 KB |
Output is correct |
31 |
Correct |
25 ms |
332 KB |
Output is correct |
32 |
Correct |
21 ms |
332 KB |
Output is correct |
33 |
Correct |
26 ms |
332 KB |
Output is correct |
34 |
Correct |
21 ms |
400 KB |
Output is correct |
35 |
Correct |
16 ms |
332 KB |
Output is correct |
36 |
Correct |
14 ms |
332 KB |
Output is correct |
37 |
Correct |
13 ms |
332 KB |
Output is correct |
38 |
Correct |
17 ms |
396 KB |
Output is correct |
39 |
Runtime error |
38 ms |
2896 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |