#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include "crocodile.h"
const ll INF = 1e18;
struct twoSet{
ll x = INF, y = INF; // x < y
bool insert(ll v){
if(v >= y) return false;
y = v;
if(x > y) swap(x, y);
return true;
}
ll get(){ return y; }
};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
vector<twoSet> dist(N);
vector<pair<int, ll>> g[N];
for(int i=0; i<M; ++i){
g[R[i][0]].emplace_back(R[i][1], L[i]);
g[R[i][1]].emplace_back(R[i][0], L[i]);
}
priority_queue<pair<ll, int>> q;
for(int i=0; i<K; ++i){
q.emplace(0, P[i]);
dist[P[i]].insert(0);
dist[P[i]].insert(0);
}
while(!q.empty()){
ll u = q.top().second, d = -q.top().first; q.pop();
if(d != dist[u].get()) continue;
for(auto &e : g[u]){
int v = e.first, w = e.second;
if(dist[v].insert(d + w)) q.emplace(-dist[v].get(), v);
}
}
return dist[0].get();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
4 ms |
972 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
4 ms |
972 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
528 ms |
67384 KB |
Output is correct |
17 |
Correct |
103 ms |
16568 KB |
Output is correct |
18 |
Correct |
135 ms |
18872 KB |
Output is correct |
19 |
Correct |
677 ms |
76976 KB |
Output is correct |
20 |
Correct |
314 ms |
52420 KB |
Output is correct |
21 |
Correct |
46 ms |
7316 KB |
Output is correct |
22 |
Incorrect |
347 ms |
48876 KB |
Output isn't correct |