#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e17 + 69;
int n, m, r[maxn][2], l[maxn], k, p[maxn];
pair<ll, ll> f[maxn];
vector<pa> g[maxn];
ll travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
priority_queue<pall, vector<pall>, greater<pall>> q;
fill_n(f, n, make_pair(oo, oo));
for(int i = 0; i < k; i++) {
f[p[i]] = {0, 0};
q.push({0, p[i]});
}
for(int i = 0; i < m; i++) {
int u = r[i][0], v = r[i][1];
g[u].pb({v, l[i]});
g[v].pb({u, l[i]});
}
while(!q.empty()) {
int u = q.top().se;
ll fu = q.top().fi;
q.pop();
if(fu != f[u].se) continue;
for(auto e:g[u]) {
int v = e.fi, w = e.se;
if(f[v].fi > fu + w) {
if(f[v].se != f[v].fi && f[v].fi < oo) q.push({f[v].fi, v});
f[v].se = f[v].fi;
f[v].fi = fu + w;
} else if(f[v].se > fu + w) {
f[v].se = fu + w;
q.push({f[v].se, v});
}
}
}
return f[0].se;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
5008 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
5008 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
6 ms |
5268 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
6 ms |
5424 KB |
Output is correct |
13 |
Correct |
6 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5012 KB |
Output is correct |
15 |
Correct |
3 ms |
5024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
5008 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
6 ms |
5268 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
6 ms |
5424 KB |
Output is correct |
13 |
Correct |
6 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5012 KB |
Output is correct |
15 |
Correct |
3 ms |
5024 KB |
Output is correct |
16 |
Correct |
361 ms |
44884 KB |
Output is correct |
17 |
Correct |
62 ms |
13644 KB |
Output is correct |
18 |
Correct |
81 ms |
14968 KB |
Output is correct |
19 |
Correct |
446 ms |
50192 KB |
Output is correct |
20 |
Correct |
254 ms |
38640 KB |
Output is correct |
21 |
Correct |
32 ms |
8960 KB |
Output is correct |
22 |
Correct |
263 ms |
34600 KB |
Output is correct |