1450. Russian Pipelines(spfa)

时间:2022-12-16 17:34:24

1450

水题 最长路

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<vector>
using namespace std;
int n,m;
vector<int>ed[];
int vis[],dis[],w[][];
void spfa(int s,int e)
{
int i;
queue<int>q;
q.push(s);
vis[s] = ;
while(!q.empty())
{
int u = q.front();
q.pop();
vis[u] = ;
for(i = ; i < (int)ed[u].size() ; i++)
{
int v = ed[u][i];
if(dis[v]<dis[u]+w[u][v])
{
dis[v] = dis[u]+w[u][v];
if(!vis[v])
{
vis[v] = ;
q.push(v);
}
}
}
}
if(dis[e])
printf("%d\n",dis[e]);
else
printf("No solution\n");
}
int main()
{
int i;
scanf("%d%d",&n,&m);
for(i = ; i <= m; i++)
{
int u,v,c;
scanf("%d%d%d",&u,&v,&c);
w[u][v] = c;
ed[u].push_back(v);
}
int s,e;
scanf("%d%d",&s,&e);
spfa(s,e);
return ;
}