#include "crocodile.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<bool>is;
vector<vector<pair<int,int>>>v;
const int INF=1e9;
vector<ll>dfs(int x,ll d = 0,int p=-1){
if(is[x]) return {d};
vector<ll>a;
for(auto [z,w]:v[x]){
if(z!=p){
vector<ll>b=dfs(z,d+w,x);
sort(b.begin(),b.end());
if(b.size()>1) a.push_back(b[1]);
else if(b.size()) a.push_back(b[0]);
}
}
return a;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
is.assign(N,false);
for(int i=0;i<K;i++) is[P[i]]=true;
v.resize(N);
for(int i=0;i<M;i++){
v[R[i][0]].push_back({R[i][1],L[i]});
v[R[i][1]].push_back({R[i][0],L[i]});
}
vector<ll>ans=dfs(0);
sort(ans.begin(),ans.end());
return ans[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |