#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define ild pair <ld, ld>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 1e5 + 2;
const int M = 10;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll base = 311;
const int BLOCK_SIZE = 400;
int n, m, k;
vector <ill> g[N];
ll travel_plan (int nn, int mm, int r[][2], int l[], int kk, int p[]){
n = nn, m = mm, k = kk;
for (int i = 0; i < m; i ++) {
ll u = r[i][0], v = r[i][1], w = l[i];
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector <ill> d(n);
for (int i = 0; i < n; i ++) d[i] = {INF, INF};
set <ill> h;
for (int i = 0, u; i < k; i ++) {
u = p[i];
h.insert({0, u});
d[u] = {0, 0};
}
vector <bool> vis(n);
while (!h.empty()) {
int u = (*h.begin()).se;
ll dis = (*h.begin()).fi;
h.erase(h.begin());
if (vis[u]) continue;
vis[u] = 1;
for (ill e: g[u]) {
int v = e.fi; ll w = e.se;
if (d[v].fi > dis + w) {
d[v] = {dis + w, d[v].fi};
h.insert({d[v].se, v});
}
else if (d[v].se > dis + w) {
d[v].se = dis + w;
h.insert({d[v].se, v});
}
}
}
return d[0].se;
}
/*
/\_/\ zzZ
(= -_-)
/ >u >u
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6776 KB |
Output is correct |
4 |
Correct |
2 ms |
6744 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6776 KB |
Output is correct |
4 |
Correct |
2 ms |
6744 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
7004 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
4 ms |
7512 KB |
Output is correct |
13 |
Correct |
4 ms |
7292 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6776 KB |
Output is correct |
4 |
Correct |
2 ms |
6744 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
7004 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
4 ms |
7512 KB |
Output is correct |
13 |
Correct |
4 ms |
7292 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
399 ms |
90328 KB |
Output is correct |
17 |
Correct |
87 ms |
25676 KB |
Output is correct |
18 |
Correct |
119 ms |
29036 KB |
Output is correct |
19 |
Correct |
539 ms |
102448 KB |
Output is correct |
20 |
Correct |
223 ms |
72664 KB |
Output is correct |
21 |
Correct |
36 ms |
14684 KB |
Output is correct |
22 |
Correct |
256 ms |
67664 KB |
Output is correct |