#include <bits/stdc++.h>
using namespace std ;
#define f(i,a,b) for(int i=a;i<b;++i)
void dfs(int i,int p,vector< vector< array<int,2> > > &g,vector<int> &best){
if( best[i] == 0 ) return ;
assert(best[i] == -1) ;
vector<int> V ;
for(auto [j,w]:g[i]) if(j!=p){
dfs(j,i,g,best) ;
V.push_back(best[j] + w) ;
}
sort(V.begin(),V.end()) ;
best[i] = V[1] ;
}
int travel_plan(int N, int M, int R[][2],int L[], int K,int P[]){
vector< vector< array<int,2> > > g(N) ;
f(i,0,M){
int u = R[i][0], v = R[i][1], w = L[i] ;
g[u].push_back({v, w}) ;
g[v].push_back({u, w}) ;
}
vector<int> best(N,-1) ;
f(i,0,K) best[P[i]] = 0 ;
dfs(0,0,g,best) ;
return best[0] ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Runtime error |
182 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Runtime error |
182 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |