This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "crocodile.h"
#include <bits/stdc++.h>
#define LL long long
#define ii pair<LL,LL>
#define F first
#define S second
using namespace std;
const int NN=1e5+100;
const int INF=1e18;
vector<ii> g[NN];
LL dp[NN];
priority_queue<LL,vector<LL>,greater<LL>> vec[NN];
priority_queue<ii,vector<ii>,greater<ii>> q;
void dijkstra()
{
while(q.empty()==0){
LL w=q.top().F;
LL u=q.top().S;
q.pop();
if(w>dp[u])continue;
for(auto x:g[u]){
vec[x.F].push(x.S+dp[u]);
LL v=vec[x.F].top();
vec[x.F].pop();
LL v2=vec[x.F].top();
if(vec[x.F].empty()==0){
if(dp[x.F]>v2){
dp[x.F]=v2;
q.push({v2,x.F});
}
}
vec[x.F].push(v);
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i=0;i<N;i++)dp[i]=INF;
for(int i=0;i<K;i++){
dp[P[i]]=0;
q.push({0,P[i]});
}
for(int i=0;i<M;i++){
LL u=R[i][0];
LL v=R[i][1];
LL w=L[i];
g[u].push_back({v,w});
g[v].push_back({u,w});
// cout<<u<<" "<<v<<" "<<w<<endl;
}
dijkstra();
LL ans=dp[0];
// for(int i=0;i<N;i++)cout<<dp[i]<<" ";cout<<endl;
return ans;
}
/*
5 4 3
0 1 2
0 2 3
3 2 1
2 4 4
1 3 4
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1 3
*/
Compilation message (stderr)
crocodile.cpp:9:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
9 | const int INF=1e18;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |