#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
vector<vector<pair<int, int>>> g;
extern int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
g.resize(N);
for(int i = 0; i < M; i++){
g[R[i][0]].push_back({R[i][1], L[i]});
g[R[i][1]].push_back({R[i][0], L[i]});
}
vector<int> vis(N, 0);
vector<pair<int, int>> dist(N, {1e9, 1e9});
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for(int i = 0; i < K; i++){
vis[P[i]] = 1;
pq.push({0, P[i]});
}
while(!pq.empty()){
int d = pq.top().first, node = pq.top().second;
pq.pop();
if(vis[node] == 0){
vis[node] = 1;
continue;
}else if(vis[node] == 2) continue;
if(node == 0) return d;
vis[node]++;
for(auto i : g[node]){
if(dist[i.first].second < d+i.second) continue;
else if(dist[i.first].first > d+i.second){
dist[i.first].second = dist[i.first].first;
dist[i.first].first = d+i.second;
}else{
dist[i.first].second = d+i.second;
}
pq.push({d+i.second, i.first});
}
}
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:15:23: warning: control reaches end of non-void function [-Wreturn-type]
15 | vector<int> vis(N, 0);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4596 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4596 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4580 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4596 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4580 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4560 KB |
Output is correct |
16 |
Correct |
271 ms |
57544 KB |
Output is correct |
17 |
Correct |
51 ms |
15956 KB |
Output is correct |
18 |
Correct |
59 ms |
17232 KB |
Output is correct |
19 |
Correct |
308 ms |
62276 KB |
Output is correct |
20 |
Correct |
212 ms |
47664 KB |
Output is correct |
21 |
Correct |
34 ms |
9308 KB |
Output is correct |
22 |
Correct |
226 ms |
46384 KB |
Output is correct |