#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define X first
#define Y second
#define sep ' '
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e5 + 10;
const ll INF = 1e9 + 10;
ll dist[MAXN], n, m;
vector<pll> adj[MAXN];
priority_queue<pll, vector<pll>, greater<pll>> pq;
pair<pll, pll> F[MAXN];
inline void check(int v) {
if (F[v].Y.X < dist[v]) {
dist[v] = F[v].Y.X;
pq.push({dist[v], v});
}
}
inline void add(pair<pll, pll>& a, pll e) {
vector<pll> vec = {a.X, a.Y, e};
sort(all(vec), less<pll>());
a.X = vec[0];
if (vec[1].Y == a.X.Y) a.Y = vec[2];
else a.Y = vec[1];
}
inline void fix(int v) {
for (auto [u, l] : adj[v]) {
add(F[u], {dist[v] + l, v});
check(u);
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
n = N, m = M;
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]});
}
fill(dist, dist + MAXN, INF);
fill(F, F + MAXN, make_pair(pll(INF, INF), pll(INF, INF)));
for (int i = 0; i < K; i++) {
int v = P[i];
dist[v] = 0;
pq.push({0, v});
}
while (!pq.empty()) {
auto [d_v, v] = pq.top();
pq.pop();
if (d_v != dist[v]) continue;
fix(v);
}
dist[0] = min(dist[0], ll(numeric_limits<int>::max()));
return dist[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
4972 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
4972 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5172 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5104 KB |
Output is correct |
12 |
Correct |
7 ms |
5484 KB |
Output is correct |
13 |
Correct |
5 ms |
5480 KB |
Output is correct |
14 |
Correct |
3 ms |
4968 KB |
Output is correct |
15 |
Correct |
3 ms |
5112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
4972 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5172 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5104 KB |
Output is correct |
12 |
Correct |
7 ms |
5484 KB |
Output is correct |
13 |
Correct |
5 ms |
5480 KB |
Output is correct |
14 |
Correct |
3 ms |
4968 KB |
Output is correct |
15 |
Correct |
3 ms |
5112 KB |
Output is correct |
16 |
Correct |
386 ms |
53096 KB |
Output is correct |
17 |
Correct |
63 ms |
15300 KB |
Output is correct |
18 |
Correct |
77 ms |
16716 KB |
Output is correct |
19 |
Correct |
470 ms |
62700 KB |
Output is correct |
20 |
Correct |
253 ms |
51920 KB |
Output is correct |
21 |
Correct |
37 ms |
9784 KB |
Output is correct |
22 |
Correct |
330 ms |
48096 KB |
Output is correct |