POJ 3169 Layout (差分约束#5)
来源:互联网 发布:软件销售代理商 编辑:程序博客网 时间:2024/05/01 09:04
当d[n] = inf 时即输出 -2;
#include <cstdio>#include <algorithm>#include <cstdlib> #include <cstring>#define N 1010 #define M 35000#define MAXQ 35000using namespace std; const int inf = (-1u >> 1); int d[N], first[N];int v[M] , w[M], next[M]; bool inq[N];int cnt[N]; int e;int q[MAXQ];int indx[N]; int t[N]; void addE(int x, int y, int c){ next[e] = first[x], first[x] = e; v[e] = y; w[e] = c; e++;}int SPFA(int s, int n){ for (int i = 1; i <= n; i++)d[i] = inf; memset(cnt, 0, sizeof(cnt)); d[s] = 0; int qs, qe; qs = qe = 0; for (int i = 1; i <= n; i++)inq[i] = false; q[qe++] = s; while (qs != qe) { int x = q[qs]; inq[x] = false; for (int e = first[x]; e != -1; e = next[e])if (d[v[e]] > d[x] + w[e]) { d[v[e]] = d[x] + w[e]; if (!inq[v[e]]) { inq[v[e]] = true; q[qe++] = v[e]; if (qe == MAXQ)qe = 0; if (++cnt[v[e]] >= n)return -1; } } qs++; if (qs == MAXQ)qs = 0; } if (d[n] == inf)return -2; return d[n]; } int main(){ int n, ml, md; int A, B, D; // FILE* fp = fopen("in.txt", "r"); scanf( "%d %d %d", &n, &ml, &md); for (int i = 0; i <= n; i++) first[i] = -1; while (ml--) { scanf( "%d %d %d", &A, &B, &D); if (A > B)A ^= B, B^= A, A ^= B; addE(A, B, D); } while (md--) { scanf( "%d %d %d", &A, &B, &D); if (A > B)A ^= B, B^= A, A ^= B; addE(B, A, -D); } printf("%d\n", SPFA(1, n)); //getchar();}
- poj 3169 Layout(差分约束)
- poj 3169 Layout(差分约束)
- POJ 3169 Layout (差分约束)
- POJ 3169 Layout(差分约束)
- poj 3169 Layout(差分约束)
- poj 3169 Layout (差分约束)
- POJ-3169 Layout(差分约束)
- poj 3169 Layout (差分约束)
- POJ 3169 Layout (差分约束#5)
- POJ 3169 Layout(差分约束系统)
- POJ 3169 Layout [差分约束]
- POJ 3169 Layout 差分约束系统
- POJ 3169 Layout 差分约束系统
- poj 3169 Layout 差分约束
- POJ 3169 Layout(差分约束系统)
- POJ 3169 Layout (差分约束spfa)
- poj 3169 Layout (差分约束+Bellman )
- poj 3169 Layout (差分约束+Bellman )
- ecmall指定后台以ajax方式处理请求
- VBA Tips:为VBA program添加数字签名
- cocos2d ccLayer响应触摸事件方法:CCStandardTouchDelegate 与 CCTargetedTouchDelegate
- <c:if>判断参数是否为空
- cocos2d学习笔记(八)物理引擎box2d之二
- POJ 3169 Layout (差分约束#5)
- 重复的固定延迟执行 java
- MFC 判断鼠标是否在控件范围内
- 访问者模式(Visitor Pattern)
- Oracle 查看有哪些表被锁住
- xss漏洞和csrf漏洞防御
- shader与cg简介
- String 类型与 char 类型比较
- poj 1275 Cashier Employment(差分约束#6)