POJ1860Currency Exchange spfa
来源:互联网 发布:网络流传的父女唱的歌 编辑:程序博客网 时间:2024/04/27 19:17
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <climits>#include <string>#include <iostream>#include <map>#include <cstdlib>#include <list>#include <set>#include <queue>#include <stack>using namespace std;int n,m,tot;int head[1000];bool vis[1000];double dist[1000];int num[1000];double money;struct bian{ int v,next; double tax,rate;}edge[1000];void add(int u,int v,double rate,double tax){ edge[tot].v=v; edge[tot].rate=rate; edge[tot].tax=tax; edge[tot].next=head[u]; head[u]=tot++;}int spfa(int s){ queue<int>q; memset(dist,0,sizeof(dist)); memset(num,0,sizeof(num)); memset(vis,0,sizeof(vis)); dist[s]=money; q.push(s); vis[s]=true; num[s]++; while(!q.empty()) { int u=q.front(); q.pop();vis[u]=false; for(int cur=head[u];cur!=-1;cur=edge[cur].next) { int v=edge[cur].v; if(dist[v]<(dist[u]-edge[cur].tax)*edge[cur].rate) { dist[v]=(dist[u]-edge[cur].tax)*edge[cur].rate; if(!vis[v]) { vis[v]=true; num[v]++; if(num[v]>=n) return 1; q.push(v); } } } } return 0;}int main(){ int a,b,s; double ab,t1,ba,t2; tot=0; cin>>n>>m>>s>>money; memset(head,-1,sizeof(head)); for(int i=0;i<m;i++) { cin>>a>>b>>ab>>t1>>ba>>t2; add(a,b,ab,t1); add(b,a,ba,t2); } if(spfa(s)) printf("YES\n"); else printf("NO\n"); return 0;}
0 0
- POJ1860Currency Exchange spfa
- poj1860Currency Exchange(spfa)
- poj1860Currency Exchange
- POJ1860Currency Exchange
- poj1860Currency Exchange
- POJ1860Currency Exchange
- poj1860Currency Exchange
- poj1860Currency Exchange(最短路)
- Currency Exchange(spfa)
- Currency Exchange(SPFA寒假)
- Currency Exchange (SPFA)
- poj1860 Currency Exchange(spfa)
- 【POJ1860】Currency Exchange【spfa判正环】
- Currency Exchange【POJ--1860】【SPFA】
- POJ 1860 Currency Exchange spfa
- Poj 1860 Currency Exchange【SPFA】
- Poj 1860 Currency Exchange ( SPFA
- [POJ 1860] Currency Exchange [spfa]
- ajax 入门经典实例
- QString int long char*之间的转换
- 浅析三层架构
- 手机webApp触摸左右滑动切换轮播图片广告
- STL--map用法
- POJ1860Currency Exchange spfa
- keil程序在外部RAM中调试的问题总结(个人的一点经验总结)
- HDU 4952 Number Transformation 规律题
- 图像处理基础知识(一)
- JPos学习
- qt里大多数可共用的设置
- NS安装笔记
- 网络经济与企业管理(一)
- asp.net中repeater控件分页