#include<bits/stdc++.h>
#include "crocodile.h"
typedef long long ll;
using namespace std;
vector<pair<ll,ll> >g[100005];
priority_queue<pair<ll,ll> >q;
ll dis[100005];
bool used[100005], ext[100005];
void dfs(int v, int p)
{
for(pair<ll, ll> u : g[v])
{
if(u.first!=p)
{
dis[u.first]=dis[v]+u.second;
dfs(u.first, v);
}
}
}
ll ans(int v, int p)
{
vector<int>w;
for(pair<ll, ll> u : g[v])
{
if(u.first==p) continue;
if(ext[u.first]) w.push_back(dis[u.first]);
else w.push_back(ans(u.first, v));
}
sort(w.begin(), w.end());
return w[1];
}
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[])
{
for(int i=0; i<m; i++)
{
g[R[i][0]].push_back({R[i][1], L[i]});
g[R[i][1]].push_back({R[i][0], L[i]});
}
for(int i=0; i<k; i++)
ext[P[i]]=1;
dis[0]=0;
dfs(0, 0);
return ans(0, 0);
}
/*
5 4 3
0 1 2
0 2 3
3 2 1
2 4 4
1 3 4
7
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Runtime error |
243 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Runtime error |
243 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |