#include <bits/stdc++.h>
using namespace std;
int solve(int N,int M,int (*edges)[2],int *times,int K,int *positions){
vector<pair<int,int>> adj[N];
for(int i = 0;i<M;++i){
adj[edges[i][0]].push_back({edges[i][1],times[i]});
adj[edges[i][1]].push_back({edges[i][0],times[i]});
}
vector<int> vis(N,0); vector<vector<int>> dist(N);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
for(int i = 0;i<K;++i){
int cur = positions[i];
vis[cur]++;
dist[cur].push_back(0); dist[cur].push_back(0);
pq.push({0,cur});
}
while(!pq.empty()){
int u = pq.top().second; int dis = pq.top().first; pq.pop();
if(vis[u] >= 2) continue;
vis[u]++;
if(vis[u] != 2) continue;
if(u == 0) return dis;
for(auto p : adj[u]){
int v = p.first;
if(dist[v].size() == 2){
sort(dist[v].begin(),dist[v].end());
if(dist[v][1] > p.second+dis){
dist[v][1] = p.second+dis;
pq.push({dist[v][1],v});
}
}
else{
dist[v].push_back(p.second+dis);
pq.push({dist[v][1],v});
}
}
}
}
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:38:1: warning: control reaches end of non-void function [-Wreturn-type]
38 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |