#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
using lol=long long int;
const lol inf=1e18+8;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
vector<vector<pair<int,lol> > > g(N);
for(int 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]});
}
priority_queue<pair<lol,int>,vector<pair<lol,int> >,greater<pair<lol,int> > > pq;
vector<lol> mn(N,inf);
vector<lol> smn(N,inf);
for(int i=0;i<K;i++)
{
pq.push({0,P[i]});
mn[P[i]]=smn[P[i]]=0;
}
while(!pq.empty())
{
auto [dist,u]=pq.top();
pq.pop();
if(dist>smn[u]) continue;
for(auto [v,w]:g[u])
{
lol nxt=min(inf,w+dist);
if(nxt<=mn[v])
{
if(mn[v]<smn[v])
{
smn[v]=min(inf,mn[v]);
mn[v]=min(inf,nxt);
pq.push({smn[v],v});
}else
{
smn[v]=min(inf,mn[v]);
mn[v]=min(inf,nxt);
}
}else if(nxt<smn[v])
{
smn[v]=min(inf,nxt);
pq.push({smn[v],v});
}
}
}
return smn[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
844 KB |
Output is correct |
13 |
Correct |
3 ms |
972 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
844 KB |
Output is correct |
13 |
Correct |
3 ms |
972 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
422 ms |
65380 KB |
Output is correct |
17 |
Correct |
70 ms |
14304 KB |
Output is correct |
18 |
Correct |
102 ms |
16564 KB |
Output is correct |
19 |
Correct |
514 ms |
72928 KB |
Output is correct |
20 |
Correct |
265 ms |
52676 KB |
Output is correct |
21 |
Correct |
35 ms |
6588 KB |
Output is correct |
22 |
Correct |
277 ms |
48328 KB |
Output is correct |