#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int INF = 2000000000;
int n, m, k;
int marc[MAXN], isExit[MAXN], dist[MAXN], dist2[MAXN];
vector<int> v[MAXN], p[MAXN];
void dijkstra();
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++){
v[R[i][0]].push_back(R[i][1]);
v[R[i][1]].push_back(R[i][0]);
p[R[i][0]].push_back(L[i]);
p[R[i][1]].push_back(L[i]);
}
for(int i = 0; i < k; i++)
isExit[P[i]] = 1;
dijkstra();
return dist2[0];
}
void dijkstra(){
set<pair<int, int> > out;
for(int i = 0; i < n; i++){
if(isExit[i]) dist[i] = 0, dist2[i] = 0;
else dist[i] = INF, dist2[i] = INF;
out.insert(make_pair(dist2[i], i));
}
while(!out.empty()){
int cur = out.begin()->second;
int curDist = out.begin()->first;
marc[cur] = 1;
out.erase(make_pair(curDist, cur));
for(unsigned long i = 0; i < v[cur].size(); i++){
int viz = v[cur][i];
int vizDist = curDist + p[cur][i];
if(marc[viz] == 1) continue;
if(vizDist < dist[viz]){
out.erase(make_pair(dist2[viz], viz));
dist2[viz] = dist[viz];
dist[viz] = vizDist;
out.insert(make_pair(dist2[viz], viz));
}
else if(vizDist < dist2[viz]){
out.erase(make_pair(dist2[viz], viz));
dist2[viz] = vizDist;
out.insert(make_pair(dist2[viz], viz));
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
7 ms |
4984 KB |
Output is correct |
3 |
Correct |
8 ms |
5112 KB |
Output is correct |
4 |
Correct |
8 ms |
5240 KB |
Output is correct |
5 |
Correct |
8 ms |
5240 KB |
Output is correct |
6 |
Correct |
8 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
5240 KB |
Output is correct |
8 |
Correct |
8 ms |
5240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
7 ms |
4984 KB |
Output is correct |
3 |
Correct |
8 ms |
5112 KB |
Output is correct |
4 |
Correct |
8 ms |
5240 KB |
Output is correct |
5 |
Correct |
8 ms |
5240 KB |
Output is correct |
6 |
Correct |
8 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
5240 KB |
Output is correct |
8 |
Correct |
8 ms |
5240 KB |
Output is correct |
9 |
Correct |
12 ms |
5372 KB |
Output is correct |
10 |
Correct |
8 ms |
5112 KB |
Output is correct |
11 |
Correct |
8 ms |
5112 KB |
Output is correct |
12 |
Correct |
12 ms |
5368 KB |
Output is correct |
13 |
Correct |
11 ms |
5496 KB |
Output is correct |
14 |
Correct |
8 ms |
5116 KB |
Output is correct |
15 |
Correct |
8 ms |
5116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
7 ms |
4984 KB |
Output is correct |
3 |
Correct |
8 ms |
5112 KB |
Output is correct |
4 |
Correct |
8 ms |
5240 KB |
Output is correct |
5 |
Correct |
8 ms |
5240 KB |
Output is correct |
6 |
Correct |
8 ms |
5112 KB |
Output is correct |
7 |
Correct |
8 ms |
5240 KB |
Output is correct |
8 |
Correct |
8 ms |
5240 KB |
Output is correct |
9 |
Correct |
12 ms |
5372 KB |
Output is correct |
10 |
Correct |
8 ms |
5112 KB |
Output is correct |
11 |
Correct |
8 ms |
5112 KB |
Output is correct |
12 |
Correct |
12 ms |
5368 KB |
Output is correct |
13 |
Correct |
11 ms |
5496 KB |
Output is correct |
14 |
Correct |
8 ms |
5116 KB |
Output is correct |
15 |
Correct |
8 ms |
5116 KB |
Output is correct |
16 |
Correct |
851 ms |
42872 KB |
Output is correct |
17 |
Correct |
189 ms |
19448 KB |
Output is correct |
18 |
Correct |
250 ms |
21204 KB |
Output is correct |
19 |
Correct |
1397 ms |
49912 KB |
Output is correct |
20 |
Correct |
366 ms |
39724 KB |
Output is correct |
21 |
Correct |
84 ms |
10616 KB |
Output is correct |
22 |
Correct |
438 ms |
36216 KB |
Output is correct |