#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; 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 |
Runtime error |
3 ms |
396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |