#include "crocodile.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define inf 987654321987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int n, m, k;
vector<pair<int, LL> > link[100010];
LL dijk[100010][3];
bool ch[100010];
priority_queue<pair<LL, int> >pq;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n=N;
m=M;
k=K;
for(int i=0; i<m; i++){
link[R[i][0]+1].pb(make_pair(R[i][1]+1, (LL)L[i]));
link[R[i][1]+1].pb(make_pair(R[i][0]+1, (LL)L[i]));
}
for(int i=1; i<=n; i++)dijk[i][1]=dijk[i][2]=inf;
for(int i=0; i<k; i++)dijk[P[i]+1][1]=dijk[P[i]+1][2]=0, pq.push(make_pair(0, +P[i]+1));
while(!pq.empty()){
int here=pq.top().S;
LL c=-pq.top().F;
pq.pop();
if(ch[here])continue;
ch[here]=true;
for(int i=0; i<link[here].size(); i++){
int next=link[here][i].F;
LL cost=link[here][i].S;
if(ch[next])continue;
if(dijk[next][1]>c+cost){
dijk[next][2]=dijk[next][1];
dijk[next][1]=c+cost;
pq.push(make_pair(-dijk[next][2], next));
}
else if(dijk[next][2]>c+cost){
dijk[next][2]=c+cost;
pq.push(make_pair(-dijk[next][2], next));
}
}
}
return (int)dijk[1][2];
}
/*
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1
3
14
*/
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<link[here].size(); i++){
~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Correct |
5 ms |
2808 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Correct |
5 ms |
2808 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
5 ms |
2808 KB |
Output is correct |
9 |
Correct |
7 ms |
3064 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
5 ms |
2936 KB |
Output is correct |
12 |
Correct |
9 ms |
3448 KB |
Output is correct |
13 |
Correct |
8 ms |
3448 KB |
Output is correct |
14 |
Correct |
5 ms |
2680 KB |
Output is correct |
15 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2808 KB |
Output is correct |
5 |
Correct |
5 ms |
2808 KB |
Output is correct |
6 |
Correct |
5 ms |
2808 KB |
Output is correct |
7 |
Correct |
5 ms |
2808 KB |
Output is correct |
8 |
Correct |
5 ms |
2808 KB |
Output is correct |
9 |
Correct |
7 ms |
3064 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
5 ms |
2936 KB |
Output is correct |
12 |
Correct |
9 ms |
3448 KB |
Output is correct |
13 |
Correct |
8 ms |
3448 KB |
Output is correct |
14 |
Correct |
5 ms |
2680 KB |
Output is correct |
15 |
Correct |
5 ms |
2808 KB |
Output is correct |
16 |
Correct |
695 ms |
85204 KB |
Output is correct |
17 |
Correct |
132 ms |
20676 KB |
Output is correct |
18 |
Correct |
171 ms |
23256 KB |
Output is correct |
19 |
Correct |
899 ms |
94340 KB |
Output is correct |
20 |
Correct |
391 ms |
67572 KB |
Output is correct |
21 |
Correct |
62 ms |
10744 KB |
Output is correct |
22 |
Correct |
445 ms |
64960 KB |
Output is correct |