#include <bits/stdc++.h>
#define ll int
#define MAXN 100010
#define llinf 1e9
using namespace std;
vector<pair<ll,ll> > G[MAXN];
pair<ll,ll> t[MAXN];
void Dijkstra(ll N,ll K,ll P[])
{
for (ll i=0;i<N;i++)
t[i]={llinf,llinf};
priority_queue<pair<ll,pair<ll,ll> >,vector<pair<ll,pair<ll,ll> > >,greater<pair<ll,pair<ll,ll> > > > q;
for (ll i=0;i<K;i++)
{
t[P[i]]={0,0};
q.push({0,{0,P[i]}});
}
while (!q.empty())
{
ll min2=q.top().first,min1=q.top().second.first,u=q.top().second.second;
q.pop();
if (t[u].first!=min2 || t[u].second!=min1)
continue;
for (auto next : G[u])
{
ll v=next.first,w=next.second;
if (t[v].second>t[u].first+w)
{
swap(t[v].first,t[v].second);
t[v].second=t[u].first+w;
if (t[v].first!=llinf)
q.push({t[v].first,{t[v].second,v}});
continue;
}
if (t[v].first>t[u].first+w)
{
t[v].first=t[u].first+w;
q.push({t[v].first,{t[v].second,v}});
}
}
}
}
ll travel_plan(ll N,ll M,ll R[][2],ll L[],ll K,ll P[])
{
for (ll i=0;i<M;i++)
{
G[R[i][0]].push_back({R[i][1],L[i]});
G[R[i][1]].push_back({R[i][0],L[i]});
}
Dijkstra(N,K,P);
return (t[0].first==llinf?-1 : t[0].first);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2660 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2672 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2660 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2672 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
4 ms |
2900 KB |
Output is correct |
10 |
Correct |
2 ms |
2664 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
5 ms |
3156 KB |
Output is correct |
13 |
Correct |
4 ms |
3156 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2660 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2672 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
4 ms |
2900 KB |
Output is correct |
10 |
Correct |
2 ms |
2664 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
5 ms |
3156 KB |
Output is correct |
13 |
Correct |
4 ms |
3156 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2676 KB |
Output is correct |
16 |
Correct |
385 ms |
57728 KB |
Output is correct |
17 |
Correct |
63 ms |
13644 KB |
Output is correct |
18 |
Correct |
96 ms |
15204 KB |
Output is correct |
19 |
Correct |
489 ms |
62096 KB |
Output is correct |
20 |
Correct |
263 ms |
49772 KB |
Output is correct |
21 |
Correct |
35 ms |
7664 KB |
Output is correct |
22 |
Correct |
261 ms |
46008 KB |
Output is correct |