#pragma once
#include <vector>
#include <iostream>
#include <set>
using namespace std;
const int N1=1e5+100;
#define ll long long
vector<pair<int,int>> ma[N1];
ll dp[N1],dip[N1][2];
ll ans[N1][2];
bool vis[N1],done_for[N1];
void dyk()
{
set<pair<ll,ll>> dist;
dist.insert({0,0});
while(dist.size()>0)
{
auto f=*begin(dist);
dist.erase(begin(dist));
for(auto [w,y]:ma[f.second])
{
if(!done_for[y] and dp[y]>(f.first+w))
{
dist.erase({dp[y],y});
dp[y]=f.first+w;
dist.insert({dp[y],y});
}
}
}
}
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]=dip[i][0]=dip[i][1]=1e11;
for(int i=0;i<m;i++)
{
ma[r[i][0]].push_back({l[i],r[i][1]});
ma[r[i][1]].push_back({l[i],r[i][0]});
}
for(int i=0;i<k;i++)
{
for(auto [w,y]:ma[p[i]])
{
if(dip[y][0]>w)
{
dip[y][1]=dip[y][0];
dip[y][0]=w;
}
else if(dip[y][1]>w)
dip[y][1]=w;
}
done_for[p[i]]=1;
}
if(done_for[0])
return 0;
dyk();
ll ans=1e11;
for(int i=0;i<n;i++)
{
ans=min(ans,dip[i][1]+dp[i]);
// ans[i][0]=dip[i][1]+dp[i];
}
// cout<<dip[0][0]<<' '<<dip[0][1]<<endl;
return ans;
}
Compilation message
crocodile.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |