#include <bits/stdc++.h>
using namespace std;
#include "crocodile.h"
const int INF = 1e9 + 1;
struct twoSet{
int x = INF, y = INF; // x < y
bool insert(int v){
if(v >= y) return false;
y = v;
if(x > y) swap(x, y);
return true;
}
int 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, int>> 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<int, 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()){
int 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 |
300 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 |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 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 |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 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 |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
832 KB |
Output is correct |
13 |
Correct |
4 ms |
840 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 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 |
2 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 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 |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
832 KB |
Output is correct |
13 |
Correct |
4 ms |
840 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
467 ms |
56756 KB |
Output is correct |
17 |
Correct |
101 ms |
14908 KB |
Output is correct |
18 |
Correct |
121 ms |
16376 KB |
Output is correct |
19 |
Correct |
618 ms |
63104 KB |
Output is correct |
20 |
Correct |
310 ms |
47300 KB |
Output is correct |
21 |
Correct |
45 ms |
6316 KB |
Output is correct |
22 |
Incorrect |
334 ms |
44720 KB |
Output isn't correct |