#include "crocodile.h"
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 1e6 + 5;
using namespace std;
vector<vector<pii>> v;
ll dist[mxN], mn[mxN],mnid[mxN];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
v.clear();
v.resize(N + 3);
for (ll i = 0; i < N; i++)
{
dist[i] = 1e18 + 5;
mn[i] = 1e18 + 5;
}
for (ll i = 0; i < M; i++)
{
v[R[i][1]].push_back({R[i][0], L[i]});
v[R[i][0]].push_back({R[i][1], L[i]});
}
priority_queue<pii, vector<pii>, greater<pii>> q;
for (ll i = 0; i < K; i++)
{
mn[P[i]] = 0;
dist[P[i]] = 0;
q.push({0, P[i]});
}
while (q.size())
{
auto u = q.top();
q.pop();
if (dist[u.S] < u.F)
continue;
for (auto x : v[u.S])
{
if (dist[x.F] > x.S + u.F && (mn[x.F] == 1e18 + 5 || mnid[x.F] == u.S))
{
mn[x.F] = min(x.S + u.F,mn[x.F]);
mnid[x.F] = u.S;
}
else if (dist[x.F] > x.S + u.F && (mn[x.F] != 1e18 + 5 && mnid[x.F] != u.S))
{
ll Mn = mn[x.F];
if(Mn > x.S + u.F){
mn[x.F] = x.S + u.F;
mnid[x.F] = u.S;
dist[x.F] = Mn;
}else{
dist[x.F] = x.S + u.F;
}
q.push({dist[x.F], x.F});
}
}
}
return dist[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
4 ms |
9148 KB |
Output is correct |
13 |
Correct |
3 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
4 ms |
9148 KB |
Output is correct |
13 |
Correct |
3 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
326 ms |
76104 KB |
Output is correct |
17 |
Correct |
58 ms |
25004 KB |
Output is correct |
18 |
Correct |
81 ms |
27064 KB |
Output is correct |
19 |
Correct |
426 ms |
85964 KB |
Output is correct |
20 |
Correct |
219 ms |
61356 KB |
Output is correct |
21 |
Correct |
29 ms |
15708 KB |
Output is correct |
22 |
Correct |
240 ms |
58200 KB |
Output is correct |