#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
//#define int long long
#include "crocodile.h"
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 2e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
int travel_plan(int n,int m,int r[][2],int l[],int k,int p[]){
vector<pi>v[n + 5];
for(int i = 0; i <= n; i++)v[i].clear();
for(int i = 0; i < m; i++){
v[r[i][0]].push_back({r[i][1], l[i]});
v[r[i][1]].push_back({r[i][0], l[i]});
}
priority_queue<pi, vector<pi>, greater<pi>>q;
pi dist[n + 5];
for(int i = 0; i < n; i++){
dist[i] = {INT_MAX, INT_MAX};
}
for(int i = 0; i < k; i++){
q.push({0, p[i]});
dist[p[i]] = {0, 0};
}
//dijkstra
while(!q.empty()){
int x = q.top().ff, y = q.top().ss;
q.pop();
if(x > dist[y].ss)continue;
for(auto it : v[y]){
int prev = dist[it.ff].ss; //prev cost
int w = it.ss;
int nw = w + x; //new cost
if(nw < dist[it.ff].ff){
dist[it.ff].ss = dist[it.ff].ff;
dist[it.ff].ff = nw;
}else
if(nw < dist[it.ff].ss){
dist[it.ff].ss = nw;
}
if(dist[it.ff].ss < prev){//if found a better way
q.push({dist[it.ff].ss, it.ff});
}
}
}
return dist[0].ss;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
526 ms |
41588 KB |
Output is correct |
17 |
Correct |
89 ms |
12408 KB |
Output is correct |
18 |
Correct |
107 ms |
13716 KB |
Output is correct |
19 |
Correct |
805 ms |
46832 KB |
Output is correct |
20 |
Correct |
326 ms |
36216 KB |
Output is correct |
21 |
Correct |
45 ms |
6008 KB |
Output is correct |
22 |
Correct |
360 ms |
32120 KB |
Output is correct |