The eighteenty day - ford
重铸华农荣光 我辈义不容辞
The eighteenth day - Bellman-ford
#include<iostream>
#include<cstring>
using namespace std;
const int N=510,M=10010;
struct Edge{
int a,b,c;
} e[M];
int dist[N],back[N];
int n,m,k;
int Bellman_ford()
{
memset(dist,0x3f,sizeof dist);
dist[1]=0;
for(int i=0;i<k;i++)
{
memcpy(back,dist,sizeof dist);
for(int j=0;j<m;j++)
{
int a=e[j].a,b=e[j].b,c=e[j].c;
dist[b]=min(dist[b],back[a]+c);
}
}
if(dist[n]>0x3f3f3f3f/2) return 0x3f3f3f3f;
return dist[n];
}
int main()
{
cin>>n>>m>>k;
for(int i=0;i<m;i++)
{
int a,b,c;
cin>>a>>b>>c;
e[i]={a,b,c};
}
int ans=Bellman_ford();
if(ans==0x3f3f3f3f) puts("impossible");
else cout<<ans;
return 0;
}