#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][2],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] = 1;
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){
if(dist[v][1] >= p.second+dis){
dist[v][1] = p.second+dis;
pq.push({p.second+dis,v});
}
}
else{
dist[v].push_back(p.second+dis);
pq.push({p.second+dis,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:37:1: warning: control reaches end of non-void function [-Wreturn-type]
37 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |