POJ 1860 Currency Exchange——spfa判正环
来源:互联网 发布:mac中百度云视频怎么看 编辑:程序博客网 时间:2024/06/07 10:42
dis初始化为0,dis[S] = V, 松弛操作为if (dis [u] < (dis[v] - c) * v) dis [u] = (dis[v] - c) * v,结束条件为dis[S] > V
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 1010;bool vis[maxn];int N, M, S;double V, dis[maxn];struct Date { int x; double C, R; Date(int xx, double cc, double rr) : x(xx), C(cc), R(rr) {}};vector<Date> G[maxn];bool spfa() { for (int i = 1; i <= N; i++) dis[i] = 0, vis[i] = false; dis[S] = V, vis[S] = true; queue<int> q; q.push(S); while (!q.empty()) { int u = q.front(); q.pop(); vis[u] = false; for (int i = 0; i < G[u].size(); i++) { int v = G[u][i].x; double c = G[u][i].C, r = G[u][i].R; if (dis[v] < (dis[u] - c) * r) { dis[v] = (dis[u] - c) * r; if (!vis[v]) vis[v] = true, q.push(v); } } if (dis[S] > V) return true; } return false;}int main() { int u, v; double C1, R1, C2, R2; while (~scanf("%d %d %d %lf", &N, &M, &S, &V)) { for (int i = 1; i <= N; i++) G[i].clear(); while (M--) { scanf("%d %d %lf %lf %lf %lf", &u, &v, &R1, &C1, &R2, &C2); G[u].push_back(Date(v, C1, R1)); G[v].push_back(Date(u, C2, R2)); } if(spfa()) printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
1 0
- POJ 1860 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]
- poj 1860 Currency Exchange (spfa)
- [POJ 1860] Currency Exchange 最短路判正环(SPFA版)
- poj 1860 Currency Exchange (SPFA)
- poj 1860 Currency Exchange(SPFA)
- POJ 1860 Currency Exchange(最短路SPFA)
- POJ 1860 Currency Exchange(spfa)
- POJ-1860-Currency Exchange-寻找正权环-spfa
- POJ 1860 - Currency Exchange(SPFA正环)
- POj 1860 Currency Exchange(SPFA判负权)
- 【POJ1860】Currency Exchange【spfa判正环】
- Poj 1860 Currency Exchange(Bellman-Ford,SPFA解单源最短路径问题)
- poj 1860 Currency Exchange (最短路变形-spfa)
- vs2017下载教程
- 1074: 百钱买百鸡
- 树状数组求逆序数
- 机器学习(1)-项目 0: 预测泰坦尼克号乘客生还率
- Ubuntu Server 16.04中文方块菱形乱码问题解决
- POJ 1860 Currency Exchange——spfa判正环
- java_3
- CentOS分区操作详解
- SVG图案
- 1023: 坑爹的黑店
- 如何关闭gnome中alt+鼠标左键移动窗口功能?
- P6Spy格式化sql
- springMvc,get请求一组数据过来接收问题
- 复数类型矩阵相乘GPU加速--pycuda