#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
struct Data{
int vertex;
pair<int, int>value;
Data(int vertex, pair<ll, ll>value){
this->vertex = vertex;
this->value = value;
}
friend bool operator <(const Data a, const Data b){
return a.value.second > b.value.second;
}
};
template<class T>bool minimize(T& a, T b){
if(a > b){
a = b;
return true;
}
return false;
}
const int lim = 1e5 + 5;
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
vector<vector<int>>e(n);
vector<pair<int, int>>dp(n, make_pair(INF, INF));
for(int i = 0; i < m; i++){
e[R[i][0]].emplace_back(i);
e[R[i][1]].emplace_back(i);
}
priority_queue<Data>pq;
for(int i = 0; i < k; i++){
pq.emplace(P[i], dp[P[i]] = make_pair(0, 0));
}
while(!pq.empty()){
auto [u, W] = pq.top();
pq.pop();
if(W == dp[u]){
for(int i = 0; i < e[u].size(); i++){
int v = R[e[u][i]][0] ^ R[e[u][i]][1] ^ u, w = W.second + L[e[u][i]];
if(minimize(dp[v], make_pair(w, dp[v].first)) || minimize(dp[v], make_pair(dp[v].first, w))){
pq.emplace(v, dp[v]);
}
}
}
}
return dp[0].second;
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:37:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | auto [u, W] = pq.top();
| ^
crocodile.cpp:40:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0; i < e[u].size(); i++){
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
4 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
4 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
325 ms |
30764 KB |
Output is correct |
17 |
Correct |
71 ms |
12340 KB |
Output is correct |
18 |
Correct |
78 ms |
13008 KB |
Output is correct |
19 |
Correct |
414 ms |
37108 KB |
Output is correct |
20 |
Correct |
199 ms |
37204 KB |
Output is correct |
21 |
Correct |
31 ms |
8736 KB |
Output is correct |
22 |
Correct |
225 ms |
37664 KB |
Output is correct |