// M
#include<bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
const int N = 100005;
int n, m, k;
ll D[N][2];
vector < pair < int , int > > Adj[N];
int travel_plan(int _n, int _m, int R[][2], int L[], int _k, int P[])
{
n = _n; m = _m; k = _k;
for (int i = 0; i < m; i ++)
{
Adj[R[i][0]].push_back({R[i][1], L[i]});
Adj[R[i][1]].push_back({R[i][0], L[i]});
}
memset(D, 63, sizeof(D));
priority_queue < pair < ll , int > > Pq;
for (int i = 0; i < k; i ++)
D[P[i]][0] = D[P[i]][1] = 0, Pq.push({0, P[i]});
while (Pq.size())
{
int v = Pq.top().second;
ll d = - Pq.top().first;
Pq.pop();
if (d > D[v][1])
continue;
for (auto e : Adj[v])
{
int u = e.first;
int w = e.second;
if (D[u][0] > D[v][1] + w)
{
D[u][1] = D[u][0];
D[u][0] = D[v][1] + w;
Pq.push({-D[u][1], u});
}
else if (D[u][1] > D[v][1] + w)
{
D[u][1] = D[v][1] + w;
Pq.push({-D[u][1], u});
}
}
}
return D[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4224 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4224 KB |
Output is correct |
4 |
Correct |
4 ms |
4352 KB |
Output is correct |
5 |
Correct |
4 ms |
4352 KB |
Output is correct |
6 |
Correct |
4 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
4352 KB |
Output is correct |
8 |
Correct |
4 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4224 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4224 KB |
Output is correct |
4 |
Correct |
4 ms |
4352 KB |
Output is correct |
5 |
Correct |
4 ms |
4352 KB |
Output is correct |
6 |
Correct |
4 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
4352 KB |
Output is correct |
8 |
Correct |
4 ms |
4352 KB |
Output is correct |
9 |
Correct |
5 ms |
4480 KB |
Output is correct |
10 |
Correct |
3 ms |
4224 KB |
Output is correct |
11 |
Correct |
4 ms |
4352 KB |
Output is correct |
12 |
Correct |
7 ms |
4736 KB |
Output is correct |
13 |
Correct |
8 ms |
4736 KB |
Output is correct |
14 |
Correct |
3 ms |
4224 KB |
Output is correct |
15 |
Correct |
4 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4224 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4224 KB |
Output is correct |
4 |
Correct |
4 ms |
4352 KB |
Output is correct |
5 |
Correct |
4 ms |
4352 KB |
Output is correct |
6 |
Correct |
4 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
4352 KB |
Output is correct |
8 |
Correct |
4 ms |
4352 KB |
Output is correct |
9 |
Correct |
5 ms |
4480 KB |
Output is correct |
10 |
Correct |
3 ms |
4224 KB |
Output is correct |
11 |
Correct |
4 ms |
4352 KB |
Output is correct |
12 |
Correct |
7 ms |
4736 KB |
Output is correct |
13 |
Correct |
8 ms |
4736 KB |
Output is correct |
14 |
Correct |
3 ms |
4224 KB |
Output is correct |
15 |
Correct |
4 ms |
4352 KB |
Output is correct |
16 |
Correct |
588 ms |
45776 KB |
Output is correct |
17 |
Correct |
118 ms |
13984 KB |
Output is correct |
18 |
Correct |
144 ms |
15344 KB |
Output is correct |
19 |
Correct |
746 ms |
52324 KB |
Output is correct |
20 |
Correct |
354 ms |
38776 KB |
Output is correct |
21 |
Correct |
54 ms |
8824 KB |
Output is correct |
22 |
Incorrect |
401 ms |
34296 KB |
Output isn't correct |