/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX / 2;
struct Edge
{
int to;
ll len;
};
struct Path
{
int to;
ll len;
};
bool operator < (const Path &p1, const Path &p2)
{
return p1.len > p2.len;
}
int travel_plan (int N, int M, int R[][2], int L[], int K, int P[])
{
vector <vector <Edge>> adj (N);
for(int i = 0; i < M; i++)
{
adj[R[i][0]].push_back(Edge{R[i][1], L[i]});
adj[R[i][1]].push_back(Edge{R[i][0], L[i]});
}
vector <bool> visited (N, false);
vector <ll> dist1 (N, INF);
vector <ll> dist2 (N, INF);
priority_queue <Path> q;
for(int i = 0; i < K; i++)
{
dist1[P[i]] = dist2[P[i]] = 0;
q.push(Path{P[i], 0});
}
while(q.empty() == false)
{
Path p = q.top();
q.pop();
if(visited[p.to] == true)
continue;
visited[p.to] = true;
for(Edge e : adj[p.to])
if(visited[e.to] == false)
{
if(dist2[p.to] + e.len <= dist1[e.to])
{
dist2[e.to] = dist1[e.to];
dist1[e.to] = dist2[p.to] + e.len;
}
else if(dist2[p.to] + e.len < dist2[e.to])
{
dist2[e.to] = dist2[p.to] + e.len;
}
if(dist2[e.to] != INF)
q.push(Path{e.to, dist2[e.to]});
}
}
return dist2[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
1228 KB |
Output is correct |
13 |
Correct |
5 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
1228 KB |
Output is correct |
13 |
Correct |
5 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
863 ms |
95924 KB |
Output is correct |
17 |
Correct |
84 ms |
17604 KB |
Output is correct |
18 |
Correct |
105 ms |
20008 KB |
Output is correct |
19 |
Correct |
938 ms |
93300 KB |
Output is correct |
20 |
Correct |
513 ms |
82160 KB |
Output is correct |
21 |
Correct |
41 ms |
8028 KB |
Output is correct |
22 |
Correct |
457 ms |
62548 KB |
Output is correct |