#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int const MAXN=1e5+10;
vector<pair<int,int>>nei[MAXN]={};
bool ex[MAXN]={},vis[MAXN]={};
bool comp(pair<int,int>a,pair<int,int>b)
{
return (a.second<=b.second);
}
int dfs(int n,int val)
{
if (ex[n])
{
return val;
}
vis[n]=1;
vector<pair<int,int>>g;
for (auto [i,w]:nei[n])
{
if (!vis[i])
{
int z=(dfs(i,val+w));
g.push_back({z,i});
}
}
sort(begin(g),end(g));
if (g.size()==1)
return g[0].first;
if (g.size()==0)
return 1e9+10;
return g[1].first;
}
int ans=1e9+10;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for (int i=0;i<M;i++)
{
nei[R[i][0]].push_back({R[i][1],L[i]});
nei[R[i][1]].push_back({R[i][0],L[i]});
}
for (int i=0;i<K;i++)
ex[P[i]]=1;
for (int i=0;i<N;i++)
sort(begin(nei[i]),end(nei[i]),comp);
return dfs(0,0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
1 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
1 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Incorrect |
3 ms |
5464 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
1 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Incorrect |
3 ms |
5464 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |