Currency Exchange -spfa判断正环

Currency Exchange

 POJ - 1860 

#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f
#define maxn 151
#define ll long long
ll n,m,s,a,b;
bool vis[maxn];
double v,dis[maxn];
double s1,s2,s3,s4;
double mmp[maxn][maxn];
double cost[maxn][maxn];
void spfa(int s)
{
    queueq;
    dis[s]=v;
    q.push(s);
    vis[s]=1;
    while(!q.empty())
    {
        int top=q.front();
        q.pop();
        vis[top]=0;
        for(int i=1; i<=n; i++)
        {
            if(dis[i]<(dis[top]-cost[top][i])*mmp[top][i])
            {
                dis[i]=(dis[top]-cost[top][i])*mmp[top][i];
                if(!vis[i])
                {
                    vis[i]=1;
                    q.push(i);
                }
                if(dis[s]>v)
                {
                    cout<<"YES"<>n>>m>>s>>v;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(i==j)
                mmp[i][j]=1;
            else
                mmp[i][j]=0;
            cost[i][j]=0;
            vis[i]=0;
            dis[i]=0;
        }
    while(m--)
    {
        cin>>a>>b>>s1>>s2>>s3>>s4;
        mmp[a][b]=s1;
        mmp[b][a]=s3;
        cost[a][b]=s2;
        cost[b][a]=s4;
//        cout<

 

你可能感兴趣的:(最短路)