bnu 33971 Funny Car Racing (spfa)
来源:互联网 发布:讲故事软件哪个好 编辑:程序博客网 时间:2024/05/16 03:23
类似最短路
#include<algorithm>#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<vector>#include <queue>#define REP(i, n) for(int i=0; i<n; i++)#define FF(i, a, b) for(int i=a; i<b; i++)#define FD(i, a, b) for(int i=a; i>=b; i--)#define CLR(a, b) memset(a, b, sizeof(a))#define PB push_backusing namespace std;const int maxn = 100010;const int INF = 100000007;int n, m, s, t;struct Node{ int to, next; int at, bt, tt;};Node adj[50050];int head[310];int tot;void init(){ tot = 0; CLR(head, -1);}void add_edge(int x, int y, int at, int bt, int tt){ adj[tot].to = y; adj[tot].at = at; adj[tot].bt = bt; adj[tot].tt = tt; adj[tot].next = head[x]; head[x] = tot++;}int dp[310];int inq[310];void spfa(){ REP(i, n + 1) dp[i] = INF; dp[s] = 0; CLR(inq, 0); inq[s] = 1; queue<int>q; while (!q.empty()) q.pop(); q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); inq[u] = 0; for (int r = head[u]; r != -1; r = adj[r].next) { if (adj[r].at < adj[r].tt) continue; int v = adj[r].to; int y = dp[u] % (adj[r].at + adj[r].bt); int x = adj[r].at - y; if (x >= adj[r].tt) { int nextv = dp[u] + adj[r].tt; if (dp[v] > nextv) { dp[v] = nextv; if (!inq[v]) inq[v] = 1, q.push(v); } } else { int nextv = dp[u] + adj[r].tt + (adj[r].at + adj[r].bt - y); if (dp[v] > nextv) { dp[v] = nextv; if (!inq[v]) inq[v] = 1, q.push(v); } } } }}int main(){ int nc = 1; int at, bt, tt; int x, y; while (~scanf("%d%d%d%d", &n, &m, &s, &t)) { init(); while (m--) { scanf("%d%d%d%d%d", &x, &y, &at, &bt, &tt); add_edge(x, y, at, bt, tt); } spfa(); printf("Case %d: %d\n", nc++, dp[t]); }}
- bnu 33971 Funny Car Racing (spfa)
- CSU 1333 Funny Car Racing(spfa)
- CSU 1333: Funny Car Racing(SPFA)13年省赛题
- 文章标题 csu1333 :Funny Car Racing(最短路 spfa)
- CSUOJ 1333 Funny Car Racing (spfa算法)
- CSU1333 Funny Car Racing(最短路,SPFA)
- 1333: Funny Car Racing(最短路用spfa)
- Funny Car Racing(最短路)
- 12661 - Funny Car Racing (最短路)
- Funny Car Racing
- Funny Car Racing CSU
- Funny Car Racing UVA
- Funny Car Racing UVA
- Funny Car Racing UVA
- uva 12661 - Funny Car Racing
- Uva-12661-Funny Car Racing
- UVA 12661 Funny Car Racing
- UVa 12661 Funny Car Racing
- Linux网络编程(4):select函数
- Java的IO操作
- Erlang-fun函数笔记
- 关于EXCEL表如何导入进DataGridView控件中的问题
- OCP-1Z0-053-V12.02-278题
- bnu 33971 Funny Car Racing (spfa)
- 面向对象的设计(二)——C++高级编程
- android monitor tool (8.0 模拟发送按键及触摸屏事件实现)
- 今天博客抽风了,我也抽风了
- <jsp:userbean>的用法
- 消除方块+不同颜色score加减分+player是否出界+鼠标控制+窗口显示得分
- android中两种上下文的区别
- Oracle删除表的几种方法及其比较
- 2013.11.07