#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
using ll = long long;
struct edge{
int u, v, w;
int oth(int o){
return u ^ v ^ o;
}
};
int travel_plan(int n, int m, int r[][2], int L[], int k, int p[]){
priority_queue<pair<int,int>> pq;
vector<vector<int>> dist(n);
for(int i = 0; i < k; i++){
pq.emplace(0, p[i]);
dist[p[i]].push_back(0);
dist[p[i]].push_back(0);
}
vector<vector<pair<int,int>>> g(n);
for(int i = 0; i < m; i++){
g[r[i][0]].emplace_back(r[i][1], L[i]);
g[r[i][1]].emplace_back(r[i][0], L[i]);
}
while(pq.size()){
auto [d, v] = pq.top(); pq.pop();
if(-d > dist[v].back()) continue;
if(v == 0) return -d;
for(auto [u, w]: g[v]){
if(dist[u].empty()){
dist[u].push_back(-d + w);
}else if(dist[u].size() == 1){
dist[u].push_back(-d + w);
sort(dist[u].begin(), dist[u].end());
pq.emplace(-dist[u][1], u);
}else{
if(-d + w < dist[u][1]){
dist[u].push_back(-d + w);
sort(dist[u].begin(), dist[u].end());
dist[u].pop_back();
pq.emplace(-dist[u][1], u);
}
}
}
}
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:13:35: warning: control reaches end of non-void function [-Wreturn-type]
13 | priority_queue<pair<int,int>> pq;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
4 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
4 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
298 ms |
56440 KB |
Output is correct |
17 |
Correct |
66 ms |
18380 KB |
Output is correct |
18 |
Correct |
68 ms |
18184 KB |
Output is correct |
19 |
Correct |
349 ms |
62944 KB |
Output is correct |
20 |
Correct |
232 ms |
47168 KB |
Output is correct |
21 |
Correct |
44 ms |
7352 KB |
Output is correct |
22 |
Incorrect |
236 ms |
45736 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |