#include <bits/stdc++.h>
using namespace std;
//#define int long long
const long long INF = 1e18;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
vector< vector< pair<long long, long long> > > Graph(n);
for(int i = 0; i < m; i++){
Graph[r[i][0]].push_back(make_pair(l[i], r[i][1]));
Graph[r[i][1]].push_back(make_pair(l[i], r[i][0]));
}
priority_queue< pair<long long, long long>, vector< pair<long long, long long> >, greater< pair<long long, long long> > > pq;
vector< vector< long long > > dist(n, vector<long long>(2, INF));
for(int i = 0; i < k; i++){
dist[p[i]][0] = dist[p[i]][1] = 0;
pq.push(make_pair(0,p[i]));
}
vector< bool > visited(n);
while(!pq.empty()){
pair<long long, long long> pa = pq.top();
pq.pop();
long long cost = pa.first;
int node = pa.second;
if(visited[node]){
continue;
}
visited[node] = true;
for(auto a : Graph[node]){
if(dist[a.second][0] >= a.first + cost){
dist[a.second][1] = dist[a.second][0];
dist[a.second][0] = a.first+cost;
pq.push(make_pair(dist[a.second][1], a.second));
}else if(dist[a.second][1] > a.first+cost){
dist[a.second][1] = a.first+cost;
pq.push(make_pair(dist[a.second][1], a.second));
}
}
}
return dist[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
484 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
484 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
6 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
484 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
6 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
787 ms |
67968 KB |
Output is correct |
17 |
Correct |
126 ms |
20972 KB |
Output is correct |
18 |
Correct |
191 ms |
22524 KB |
Output is correct |
19 |
Correct |
1100 ms |
78176 KB |
Output is correct |
20 |
Correct |
351 ms |
53140 KB |
Output is correct |
21 |
Correct |
56 ms |
8696 KB |
Output is correct |
22 |
Correct |
443 ms |
50504 KB |
Output is correct |