#include <bits/stdc++.h>
#define MAX 101000
typedef std::pair<int,int> pii;
std::vector<pii> con[MAX];
int travel_plan(int N,int M,int R[][2],int* L,int K,int* P)
{
for(auto&x:con)x.clear();
for(int i=0;i!=M;++i){
int a=R[i][0],b=R[i][1],c=L[i];
con[a].push_back({b,c});
con[b].push_back({a,c});
}
std::priority_queue<pii,std::vector<pii>,std::greater<pii>> queue;
int peso_min[N]={};
int visitas[N]={};
for(int i=0;i!=K;++i){
int x=P[i];
visitas[x]=1;queue.push({0,x});
}
while(queue.size()){
auto _=queue.top();
queue.pop();
if(!visitas[_.second]){
++visitas[_.second];
}else if(visitas[_.second]==1){
++visitas[_.second];
peso_min[_.second]=_.first;
for(auto&k:con[_.second]){
queue.push({k.second+_.first,k.first});
}
}
}
return peso_min[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
4 ms |
2764 KB |
Output is correct |
5 |
Correct |
4 ms |
2764 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
4 ms |
2764 KB |
Output is correct |
5 |
Correct |
4 ms |
2764 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
5 ms |
3068 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
4 ms |
2764 KB |
Output is correct |
12 |
Correct |
12 ms |
3532 KB |
Output is correct |
13 |
Correct |
8 ms |
3532 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
4 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
4 ms |
2764 KB |
Output is correct |
5 |
Correct |
4 ms |
2764 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
5 ms |
3068 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
4 ms |
2764 KB |
Output is correct |
12 |
Correct |
12 ms |
3532 KB |
Output is correct |
13 |
Correct |
8 ms |
3532 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
4 ms |
2764 KB |
Output is correct |
16 |
Correct |
1090 ms |
62596 KB |
Output is correct |
17 |
Correct |
94 ms |
13748 KB |
Output is correct |
18 |
Correct |
140 ms |
15244 KB |
Output is correct |
19 |
Correct |
1213 ms |
65248 KB |
Output is correct |
20 |
Correct |
729 ms |
59212 KB |
Output is correct |
21 |
Correct |
50 ms |
7672 KB |
Output is correct |
22 |
Correct |
626 ms |
38400 KB |
Output is correct |