//#include "grader.cpp"
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std ;
const int MAX = 1e5 + 10 ;
pair<int , int> dist[MAX] ;
vector< vector< pair<int , int> > >adj(MAX) ;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
memset(dist , -1 , sizeof(dist)) ;
for(int i = 0 ; i < M ; ++i)
{
int x = R[i][0] , y = R[i][1] ;
adj[x].push_back({y , L[i]*1ll}) ;
adj[y].push_back({x, L[i] * 1ll}) ;
}
priority_queue< pair<int , int> , vector< pair<int , int> > , greater< pair<int , int> > >q ;
for(int i = 0 ; i < K ; ++i)
{
dist[P[i]] = {0 , 0} ;
q.push({0ll, P[i]}) ;
}
while(!q.empty())
{
pair<int, int>p = q.top() ;
q.pop() ;
int node = p.second ;
int cost = p.first ;
if(cost > dist[node].second)
continue ;
for(auto &child : adj[node])
{
int to = child.first ;
int ncost = cost + child.second ;
int prv = dist[to].second ;
if(ncost < dist[to].first || dist[to].first == -1)
dist[to].second = dist[to].first , dist[to].first = ncost ;
else if(ncost < dist[to].second || dist[to].second == -1)
dist[to].second = ncost ;
if(dist[to].second < prv || (prv == -1 && dist[to].second != -1))
q.push({dist[to].second, to}) ;
}
}
return dist[0].second ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
7 ms |
3456 KB |
Output is correct |
4 |
Correct |
7 ms |
3584 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
7 ms |
3584 KB |
Output is correct |
7 |
Correct |
7 ms |
3584 KB |
Output is correct |
8 |
Correct |
7 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
7 ms |
3456 KB |
Output is correct |
4 |
Correct |
7 ms |
3584 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
7 ms |
3584 KB |
Output is correct |
7 |
Correct |
7 ms |
3584 KB |
Output is correct |
8 |
Correct |
7 ms |
3584 KB |
Output is correct |
9 |
Correct |
8 ms |
3712 KB |
Output is correct |
10 |
Correct |
6 ms |
3456 KB |
Output is correct |
11 |
Correct |
7 ms |
3584 KB |
Output is correct |
12 |
Correct |
10 ms |
3968 KB |
Output is correct |
13 |
Correct |
10 ms |
3968 KB |
Output is correct |
14 |
Correct |
7 ms |
3456 KB |
Output is correct |
15 |
Correct |
7 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
7 ms |
3456 KB |
Output is correct |
4 |
Correct |
7 ms |
3584 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
7 ms |
3584 KB |
Output is correct |
7 |
Correct |
7 ms |
3584 KB |
Output is correct |
8 |
Correct |
7 ms |
3584 KB |
Output is correct |
9 |
Correct |
8 ms |
3712 KB |
Output is correct |
10 |
Correct |
6 ms |
3456 KB |
Output is correct |
11 |
Correct |
7 ms |
3584 KB |
Output is correct |
12 |
Correct |
10 ms |
3968 KB |
Output is correct |
13 |
Correct |
10 ms |
3968 KB |
Output is correct |
14 |
Correct |
7 ms |
3456 KB |
Output is correct |
15 |
Correct |
7 ms |
3584 KB |
Output is correct |
16 |
Correct |
542 ms |
41736 KB |
Output is correct |
17 |
Correct |
96 ms |
10744 KB |
Output is correct |
18 |
Correct |
114 ms |
12192 KB |
Output is correct |
19 |
Correct |
663 ms |
45168 KB |
Output is correct |
20 |
Correct |
344 ms |
37840 KB |
Output is correct |
21 |
Correct |
47 ms |
7192 KB |
Output is correct |
22 |
Correct |
360 ms |
32632 KB |
Output is correct |