#include <bits/stdc++.h>
using namespace std;
int solve(int N,int M,int (*edges)[2],int* L,int K,int *exits){
vector<pair<int,int>> adj[N];
for(int i = 0;i<M;++i){
int a = edges[i][0], b = edges[i][1], c = L[i];
adj[a].push_back({b,c}); adj[b].push_back({a,c});
}
vector<vector<int>> dist(N); vector<int> vis(N,0);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
for(int i = 0;i<K;++i){
pq.push({0,exits[i]});
dist[exits[i]].push_back(0); dist[exits[i]].push_back(0);
vis[exits[i]]++;
}
while(!pq.empty()){
int u = pq.top().second; int cur = pq.top().first; pq.pop();
if(vis[u] >= 2) continue;
vis[u]++;
if(vis[u] != 2) continue;
if(u == 0) return cur;
for(auto p : adj[u]){
if(dist[p.first].size() == 2){
sort(dist[p.first].begin(),dist[p.first].end());
if(cur+p.second < dist[p.first][1]){
dist[p.first].pop_back();
dist[p.first].push_back(cur+p.second);
pq.push({cur+p.second,p.first});
}
}
else{
dist[p.first].push_back(cur+p.second);
pq.push({cur+p.second,p.first});
}
}
}
}
int travel_plan(int n,int m,int (*r)[2],int* l,int k,int *p){
return solve(n,m,r,l,k,p);
}
Compilation message
crocodile.cpp: In function 'int solve(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
37 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
804 KB |
Output is correct |
13 |
Correct |
3 ms |
832 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
804 KB |
Output is correct |
13 |
Correct |
3 ms |
832 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
428 ms |
57644 KB |
Output is correct |
17 |
Correct |
88 ms |
18768 KB |
Output is correct |
18 |
Correct |
97 ms |
18540 KB |
Output is correct |
19 |
Correct |
516 ms |
63108 KB |
Output is correct |
20 |
Correct |
275 ms |
47308 KB |
Output is correct |
21 |
Correct |
40 ms |
7500 KB |
Output is correct |
22 |
Correct |
301 ms |
45740 KB |
Output is correct |