#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vi;
const int MAXN = 111111;
int visit[MAXN]; vi linkd[MAXN]; priority_queue<ii> pq;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i=0; i<N; i++) linkd[i].clear();
memset( visit, 0, sizeof visit);
for(int i=0; i<M; i++){
linkd[ R[i][0] ].push_back( { R[i][1], L[i] } );
linkd[ R[i][1] ].push_back( { R[i][0], L[i] } );
}
for(int i=0; i<K; i++) pq.push( { 0, P[i] } ), visit[ P[i] ] = 1;
while(!pq.empty()){
int here = pq.top().second, d = -pq.top().first; pq.pop();
if( ++visit[here] != 2 ) continue;
if( here == 0 ) return d;
for(auto it : linkd[here])
pq.push( { -d-it.second, it.first } );
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
122144 KB |
Output is correct |
2 |
Correct |
0 ms |
122144 KB |
Output is correct |
3 |
Correct |
0 ms |
122144 KB |
Output is correct |
4 |
Correct |
0 ms |
122144 KB |
Output is correct |
5 |
Correct |
0 ms |
122144 KB |
Output is correct |
6 |
Correct |
0 ms |
122144 KB |
Output is correct |
7 |
Correct |
2 ms |
122144 KB |
Output is correct |
8 |
Correct |
0 ms |
122144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
122408 KB |
Output is correct |
2 |
Correct |
0 ms |
122144 KB |
Output is correct |
3 |
Correct |
0 ms |
122144 KB |
Output is correct |
4 |
Correct |
6 ms |
122760 KB |
Output is correct |
5 |
Correct |
0 ms |
122824 KB |
Output is correct |
6 |
Correct |
0 ms |
122144 KB |
Output is correct |
7 |
Correct |
0 ms |
122144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
582 ms |
171776 KB |
Output is correct |
2 |
Correct |
113 ms |
126764 KB |
Output is correct |
3 |
Correct |
105 ms |
127952 KB |
Output is correct |
4 |
Correct |
534 ms |
161808 KB |
Output is correct |
5 |
Correct |
405 ms |
169612 KB |
Output is correct |
6 |
Correct |
56 ms |
124388 KB |
Output is correct |
7 |
Correct |
769 ms |
141200 KB |
Output is correct |