#include "crocodile.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
int travel_plan (int n, int m, int r[][2], int l[], int k, int p[]) {
//make graph
vector<pair<int, int>> g[n];
for (int i = 0; i < m; i++) {
int u = r[i][0], v = r[i][1];
g[u].push_back(make_pair(v, l[i]));
g[v].push_back(make_pair(u, l[i]));
}
//dijkstra
vector<bool> vis(n, false);
vector<int> dist(n, INF), dist2(n, INF);
priority_queue<pair<int, int>> pq;
for (int i = 0; i < k; i++) {
pq.push(make_pair(0, p[i]));
dist[p[i]] = dist2[p[i]] = 0;
}
while (!pq.empty()) {
auto v = pq.top();
pq.pop();
if (vis[v.s]) continue;
vis[v.s] = true;
for (auto u : g[v.s]) {
if (dist[u.f] > dist2[v.s] + u.s) {
dist2[u.f] = dist[u.f];
dist[u.f] = dist2[v.s] + u.s;
pq.push(make_pair(-dist2[u.f], u.f));
} else if (dist2[u.f] > dist2[v.s] + u.s) {
dist2[u.f] = dist2[v.s] + u.s;
pq.push(make_pair(-dist2[u.f], u.f));
}
}
}
return dist2[0];
}/*
int main () {
int n, m, k;
cin >> n >> m >> k;
int l[m], r[m][2], p[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];
}
cout << travel_plan(n, m, r, l, k, p) << " solution " << '\n';
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
4 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
4 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
488 ms |
57084 KB |
Output is correct |
17 |
Correct |
105 ms |
14952 KB |
Output is correct |
18 |
Correct |
131 ms |
16488 KB |
Output is correct |
19 |
Correct |
615 ms |
63460 KB |
Output is correct |
20 |
Correct |
311 ms |
47212 KB |
Output is correct |
21 |
Correct |
61 ms |
6508 KB |
Output is correct |
22 |
Correct |
341 ms |
44780 KB |
Output is correct |