//#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int k_N = 1e5 + 3;
const int k_Inf = 1e9 + 1;
int n, m, k;
vector<pair<int, int>> adj[k_N];
bool e[k_N];
pair<int, int> d[k_N];
bool in_q[k_N];
void spfa(){
queue<int> q;
for(int i = 0; i < n; ++i){
in_q[i] = false;
d[i] = {k_Inf, k_Inf};
}
for(int i = 0; i < n; ++i){
if(e[i]){
q.push(i);
in_q[i] = true;
d[i] = {0, 0};
}
}
while(!q.empty()){
int u = q.front();
q.pop();
in_q[u] = false;
//cout << u << " - " << d[u].first << " " << d[u].second << "\n";
for(auto [to, c]: adj[u]){
int new_d = d[u].second + c;
if(d[to].second > new_d){
d[to].second = new_d;
if(d[to].first > d[to].second)
swap(d[to].first, d[to].second);
if(!in_q[to] && d[to].second != k_Inf){
in_q[to] = true;
q.push(to);
}
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n = N;
m = M;
k = K;
for(int i = 0; i < m; ++i){
adj[R[i][0]].push_back({R[i][1], L[i]});
adj[R[i][1]].push_back({R[i][0], L[i]});
}
for(int i = 0; i < k; ++i)
e[P[i]] = true;
spfa();
return d[0].second;
}
/*
5 4 3
0 1 2
0 2 3
3 2 1
2 4 4
1 3 4
7
*/
/*
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1 3
14
*/
Compilation message
crocodile.cpp: In function 'void spfa()':
crocodile.cpp:40:18: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for(auto [to, c]: adj[u]){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |