1162. Currency Exchange

http://acm.timus.ru/problem.aspx?space=1&num=1162

被这句话害了 "Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence."

根本没有意义  直径 spfa 就行

代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include <iomanip>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
const int N=106;
int head[N],I;
struct node
{
    double r,c;
    int j,next;
}side[N*2];
double dist[N];
void add(int i,int j,double r,double c)
{
    side[I].j=j;
    side[I].c=c;
    side[I].r=r;
    side[I].next=head[i];
    head[i]=I++;
}
bool spfa(int s,double k,int n)
{
    int num[N];
    bool in[N];
    memset(num,0,sizeof(num));
    memset(in,false,sizeof(in));
    queue<int>qt;
    for(int i=1;i<=n;++i)
    dist[i]=0.0;
    dist[s]=k;
    qt.push(s);
    num[s]=1;
    while(!qt.empty())
    {
        int x=qt.front();qt.pop();
        in[x]=false;
        if(x==s&&dist[x]>k)
        return true;
        for(int t=head[x];t!=-1;t=side[t].next)
        {
            int j=side[t].j;
            if(dist[j]<(dist[x]-side[t].c)*side[t].r)
            {
                dist[j]=(dist[x]-side[t].c)*side[t].r;
                while(!in[j])
                {
                    ++num[j];
                    if(num[j]>=n)
                    return true;
                    in[j]=true;
                    qt.push(j);
                }
            }
        }
    }
    return false;
}
int main()
{
    //freopen("data.in","r",stdin);
    int n,m,s;
    double k;
    while(cin>>n>>m>>s>>k)
    {
        memset(head,-1,sizeof(head));
        I=0;
        while(m--)
        {
            int a,b;
            double rab,cab,rba,cba;
            cin>>a>>b>>rab>>cab>>rba>>cba;
            add(a,b,rab,cab);
            add(b,a,rba,cba);
        }
        if(spfa(s,k,n))
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/liulangye/archive/2012/11/23/2784883.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值