洛谷 P4568 [JLOI2011]飞行路线 分层图 最短路 dijkstra

https://www.luogu.org/problem/P4568

https://blog.csdn.net/aiwo1376301646/article/details/100691298

1：因为这道题目的思路和https://blog.csdn.net/aiwo1376301646/article/details/100691298一模一样，因此这里不再重复

``````#include <bits/stdc++.h>

using namespace std;
const int maxn=1e4*12+1,inf=0x3f3f3f3f;
int n,m,k,s,t,a,b,c,d[maxn],ans;
vector<pair<int,int> >e[maxn];

inline void add_edge(int f,int t,int v)
{
e[f].push_back(make_pair(t,v));
e[t].push_back(make_pair(f,v));
e[f].push_back(make_pair(t+n,0));
e[t].push_back(make_pair(f+n,0));
}

inline void dijkstra(int s)
{
memset(d,inf,sizeof(d));
priority_queue<pair<int,int> >q;
d[s]=0;
q.push(make_pair(-d[s],s));
while(!q.empty())
{
int now=q.top().second;
q.pop();
for(int i=0;i<e[now].size();i++)
{
int v=e[now][i].first;
if(d[v]>d[now]+e[now][i].second)
{
d[v]=d[now]+e[now][i].second;
q.push(make_pair(-d[v],v));
}
}
}
}

int main()
{
ios::sync_with_stdio(0);
cin>>n>>m>>k>>s>>t;
s++;
t++;
for(int i=1;i<=m;i++)
{
cin>>a>>b>>c;
a++;
b++;
for(int j=1;j<=k;j++)
{
}
}
dijkstra(s);
ans=d[t];
for(int i=1;i<=k;i++)
{
ans=min(ans,d[t+n*i]);
}
cout<<ans<<endl;
return 0;
}``````