#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
using int64 = long long;
const int MAXN = 1e5;
const int64 INF = 1e18L;
bitset<MAXN> is_exit, viz;
vector<pair<int,int>> G[MAXN];
int64 d1[MAXN], d2[MAXN];
int Dijkstra(int n) {
priority_queue<pair<int64,int>, vector<pair<int64,int>>, greater<pair<int64,int>>> pq;
for (int u = 0; u < n; ++u)
if (is_exit[u])
pq.emplace(0, u);
else d1[u] = d2[u] = INF;
while (!pq.empty()) {
int64 d;
int u;
tie(d, u) = pq.top();
pq.pop();
if (viz[u])
continue;
viz[u] = true;
for (auto it : G[u]) {
int v, w;
tie(v, w) = it;
if (viz[v])
continue;
int64 cost = d + w;
if (d1[v] >= cost) {
d2[v] = d1[v];
d1[v] = cost;
} else if (d2[v] > cost)
d2[v] = cost;
if (d2[v] != INF)
pq.emplace(d2[v], v);
}
}
return d2[0];
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for (int i = 0; i < M; ++i) {
int u = R[i][0], v = R[i][1], w = L[i];
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
}
for (int i = 0; i < K; ++i)
is_exit[P[i]] = true;
return Dijkstra(N);
}
/* int n, m, R[MAXN][2], L[MAXN], k, P[MAXN], sol;
void fastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main() {
fastIO();
cin >> n >> m >> k;
for (int i = 0; i < m; ++i)
cin >> R[i][0] >> R[i][1] >> L[i];
for (int i = 0; i < k; ++i)
cin >> P[i];
cin >> sol;
int ans = travel_plan(n, m, R, L, k, P);
if (ans == sol)
cout << "OK\n";
else {
cout << "WA\n";
cout << "USER OUTPUT: " << ans << '\n';
cout << "EXPECTED ANSWER: " << sol << '\n';
}
return 0;
} */
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
2892 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
6 ms |
3156 KB |
Output is correct |
13 |
Correct |
6 ms |
3276 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
2892 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
6 ms |
3156 KB |
Output is correct |
13 |
Correct |
6 ms |
3276 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
16 |
Correct |
672 ms |
56972 KB |
Output is correct |
17 |
Correct |
77 ms |
11164 KB |
Output is correct |
18 |
Correct |
99 ms |
12532 KB |
Output is correct |
19 |
Correct |
766 ms |
51728 KB |
Output is correct |
20 |
Correct |
465 ms |
45008 KB |
Output is correct |
21 |
Correct |
40 ms |
6384 KB |
Output is correct |
22 |
Correct |
436 ms |
32340 KB |
Output is correct |