#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
using namespace std;
struct edg
{
int x, w;
bool operator <(const edg &a) const
{
return w > a.w;
}
};
vector<edg> arr[100010];
edg dis[100010][2];
int INF = 1e9 + 10;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i = 0; i < M; i++)
{
int x = R[i][0];
int y = R[i][1];
int w = L[i];
arr[x].push_back({ y, w });
arr[y].push_back({ x, w });
}
for(int i = 0; i < N; i++)
dis[i][0] = dis[i][1] = { i, INF };
priority_queue<edg> pq;
for(int i = 0; i < K; i++)
{
int x = P[i];
dis[x][0] = dis[x][1] = { x, 0 };
pq.push({ x, 0 });
}
while(!pq.empty())
{
int x = pq.top().x;
int w = pq.top().w;
pq.pop();
if(w > dis[x][1].w)
continue;
for(edg e : arr[x])
{
int nw = w + e.w;
if(nw < dis[e.x][0].w)
{
if(x == dis[e.x][0].x)
dis[e.x][0].w = nw;
else
{
dis[e.x][1] = dis[e.x][0];
dis[e.x][0] = { x, nw };
if(dis[e.x][1].w != INF)
pq.push({ e.x, dis[e.x][1].w });
}
}
else if(nw < dis[e.x][1].w && x != dis[e.x][0].x)
{
dis[e.x][1] = { x, nw };
if(dis[e.x][1].w != INF)
pq.push({ e.x, dis[e.x][1].w });
}
}
}
assert(dis[0][1].w != INF);
return dis[0][1].w;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
5 ms |
2792 KB |
Output is correct |
4 |
Correct |
5 ms |
2908 KB |
Output is correct |
5 |
Correct |
5 ms |
2944 KB |
Output is correct |
6 |
Correct |
4 ms |
2944 KB |
Output is correct |
7 |
Correct |
4 ms |
2944 KB |
Output is correct |
8 |
Correct |
5 ms |
2944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
5 ms |
2792 KB |
Output is correct |
4 |
Correct |
5 ms |
2908 KB |
Output is correct |
5 |
Correct |
5 ms |
2944 KB |
Output is correct |
6 |
Correct |
4 ms |
2944 KB |
Output is correct |
7 |
Correct |
4 ms |
2944 KB |
Output is correct |
8 |
Correct |
5 ms |
2944 KB |
Output is correct |
9 |
Correct |
6 ms |
3212 KB |
Output is correct |
10 |
Correct |
4 ms |
3212 KB |
Output is correct |
11 |
Correct |
5 ms |
3212 KB |
Output is correct |
12 |
Correct |
9 ms |
3408 KB |
Output is correct |
13 |
Correct |
7 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
5 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
5 ms |
2792 KB |
Output is correct |
4 |
Correct |
5 ms |
2908 KB |
Output is correct |
5 |
Correct |
5 ms |
2944 KB |
Output is correct |
6 |
Correct |
4 ms |
2944 KB |
Output is correct |
7 |
Correct |
4 ms |
2944 KB |
Output is correct |
8 |
Correct |
5 ms |
2944 KB |
Output is correct |
9 |
Correct |
6 ms |
3212 KB |
Output is correct |
10 |
Correct |
4 ms |
3212 KB |
Output is correct |
11 |
Correct |
5 ms |
3212 KB |
Output is correct |
12 |
Correct |
9 ms |
3408 KB |
Output is correct |
13 |
Correct |
7 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
5 ms |
3408 KB |
Output is correct |
16 |
Correct |
612 ms |
41620 KB |
Output is correct |
17 |
Correct |
101 ms |
41620 KB |
Output is correct |
18 |
Correct |
138 ms |
41620 KB |
Output is correct |
19 |
Correct |
785 ms |
46104 KB |
Output is correct |
20 |
Correct |
381 ms |
46104 KB |
Output is correct |
21 |
Correct |
47 ms |
46104 KB |
Output is correct |
22 |
Correct |
364 ms |
46104 KB |
Output is correct |