#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]});
}
//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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 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 |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 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 |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
896 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 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 |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
896 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |