#include "crocodile.h"
#include <bits/stdc++.h>
#define MAXN 100005
#define MAXM 1000005
#define INF (1LL << 60LL)
using namespace std;
typedef long long ll;
struct Nodes
{
int node;
ll a, b;
bool operator < ( const Nodes& _x ) const
{
if ( b == _x.b )
{
if ( a == _x.a )
return node > _x.node;
return a > _x.a;
}
return b > _x.b;
}
};
int N, M, K, R[MAXM][2], L[MAXM], P[MAXN], visited[MAXN];
ll A[MAXN], B[MAXN];
vector < pair < int, ll > > Graph[MAXN];
priority_queue < Nodes > PQ;
int travel_plan ( int n, int m, int r[][2], int l[], int k, int p[] )
{
N = n;
for ( int i = 0; i < N; i++ )
A[i] = INF, B[i] = INF;
M = m;
for ( int i = 0; i < M; i++ )
R[i][0] = r[i][0], R[i][1] = r[i][1], L[i] = l[i];
K = k;
for ( int i = 0; i < K; i++ )
P[i] = p[i], PQ.push ( {P[i], 0, 0 } ), A[P[i]] = 0, B[P[i]] = 0;
for ( int i = 0; i < M; i++ )
{
Graph[R[i][0]].push_back ( {R[i][1], L[i]} );
Graph[R[i][1]].push_back ( {R[i][0], L[i]} );
}
while ( !PQ.empty() )
{
auto aux = PQ.top();
PQ.pop();
if ( visited[aux.node] )
continue;
visited[aux.node] = 1;
for ( auto i : Graph[aux.node] )
{
ll tmp = i.second + B[aux.node];
if ( tmp < A[i.first] )
swap ( A[i.first], B[i.first] ), A[i.first] = tmp;
else if ( tmp < B[i.first] )
B[i.first] = tmp;
if ( !visited[i.first] )
PQ.push ( {i.first, A[i.first], B[i.first] } );
}
}
return B[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2816 KB |
Output is correct |
4 |
Correct |
5 ms |
2816 KB |
Output is correct |
5 |
Correct |
4 ms |
2816 KB |
Output is correct |
6 |
Correct |
5 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2816 KB |
Output is correct |
4 |
Correct |
5 ms |
2816 KB |
Output is correct |
5 |
Correct |
4 ms |
2816 KB |
Output is correct |
6 |
Correct |
5 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
3328 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
6 ms |
2944 KB |
Output is correct |
12 |
Correct |
9 ms |
3840 KB |
Output is correct |
13 |
Correct |
9 ms |
3968 KB |
Output is correct |
14 |
Correct |
4 ms |
2816 KB |
Output is correct |
15 |
Correct |
5 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2816 KB |
Output is correct |
4 |
Correct |
5 ms |
2816 KB |
Output is correct |
5 |
Correct |
4 ms |
2816 KB |
Output is correct |
6 |
Correct |
5 ms |
2816 KB |
Output is correct |
7 |
Correct |
5 ms |
2816 KB |
Output is correct |
8 |
Correct |
5 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
3328 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
6 ms |
2944 KB |
Output is correct |
12 |
Correct |
9 ms |
3840 KB |
Output is correct |
13 |
Correct |
9 ms |
3968 KB |
Output is correct |
14 |
Correct |
4 ms |
2816 KB |
Output is correct |
15 |
Correct |
5 ms |
2944 KB |
Output is correct |
16 |
Correct |
1340 ms |
117064 KB |
Output is correct |
17 |
Correct |
116 ms |
23532 KB |
Output is correct |
18 |
Correct |
155 ms |
26240 KB |
Output is correct |
19 |
Correct |
1529 ms |
121860 KB |
Output is correct |
20 |
Correct |
715 ms |
91920 KB |
Output is correct |
21 |
Correct |
57 ms |
11896 KB |
Output is correct |
22 |
Correct |
531 ms |
76404 KB |
Output is correct |