#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
int travel_plan(int N,int M,int R[][2],int L[],int K,int P[]) {
vector<vector<pli>> gr(N);
for(int i=0;i<M;++i) {
gr[R[i][0]].push_back({L[i],R[i][1]});
gr[R[i][1]].push_back({L[i],R[i][0]});
}
vector<bool> vis(N);
priority_queue<pli,vector<pli>,greater<pli>> pq;
vector<vector<ll>> dist(N);
for(int i=0;i<K;++i) {
vis[P[i]]=1;
dist[P[i]].push_back(0);
for(pli p:gr[P[i]]) {
ll ed=p.first;
int v=p.second;
pq.push({ed,v});
}
}
while(!pq.empty()) {
ll d=pq.top().first;
int u=pq.top().second;
dist[u].push_back(d);
pq.pop();
if(dist[u].size()<2||vis[u]) continue;
vis[u]=1;
for(pli p:gr[u]) {
int v=p.second;
ll ed=p.first;
if(vis[v]) continue;
pq.push({ed+dist[u][1],v});
}
}
return dist[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 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 |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
960 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
1364 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 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 |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
960 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
1364 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
713 ms |
92328 KB |
Output is correct |
17 |
Correct |
86 ms |
21516 KB |
Output is correct |
18 |
Correct |
115 ms |
23232 KB |
Output is correct |
19 |
Correct |
822 ms |
96916 KB |
Output is correct |
20 |
Correct |
449 ms |
84984 KB |
Output is correct |
21 |
Correct |
41 ms |
9716 KB |
Output is correct |
22 |
Correct |
434 ms |
65480 KB |
Output is correct |