[poj3159]
来源:互联网 发布:网络里麻瓜是什么意思 编辑:程序博客网 时间:2024/06/06 18:45
题意:n个人,m个信息,每行的信息是3个数字,A,B,C,表示B比A多出来的糖果不超过C个,问你,n号人最多比1号人多几个糖果
solution
spfa+差分约束系统
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <stack>using namespace std;#define N 30010#define M 150010int nxt[M], to[M], vl[M], head[N], dist[N];int n, cnt = 0;bool vis[N];void addeage( int u, int v, int w ){ nxt[++cnt] = head[u], to[cnt] = v, vl[cnt] = w, head[u] = cnt;}int spfa( int t ){ stack<int> q; while ( !q.empty() ) q.pop(); q.push(1); memset( dist, 0x3f3f3f, sizeof(dist)); memset( vis, false, sizeof(vis)); dist[1] = 0; vis[1] = true; while ( !q.empty() ){ int cur = q.top(); q.pop(); vis[ cur ] = false; for ( int i = head[ cur ]; i; i = nxt[i]){ int v = to[i], w = vl[i]; if ( dist[v] > dist[cur] + w ){ dist[v] = dist[cur] + w; if ( !vis[v] ){ vis[v] = true; q.push( v ); } } } } return dist[t];}int main(){ int n, m, a, b, c; scanf( "%d%d", &n, &m); cnt = 0; for ( int i = 1; i <= m; i++ ){ scanf( "%d%d%d", &a, & b, &c); addeage( a, b, c); } printf( "%d", spfa(n)); return 0;}
阅读全文
0 0
- poj3159
- poj3159
- poj3159
- [poj3159]
- poj3159 Candies
- poj3159 Candies
- poj3159 Candies
- 【poj3159】 Candies
- [POJ3159]candies
- POJ3159::SPFA
- poj3159——Candies
- poj3159(spfa+栈)
- poj3159(差分约束)
- POJ3159——Candies
- poj3159 Candies(SPFA+stack)
- poj3159 dijktstra+heap
- poj3159(spfa)
- poj3159 candies dijkstra
- python中运行错误: 'utf-8' codec can't decode byte 0xc8'
- 【POJ3666】Making the Grade
- 使用html方式在博客中添加数学公式
- Java判断List中有无重复元素
- 关于HTTP请求的论述
- [poj3159]
- checkbox多项选择当前的position信息提交
- 剑指offer的java实现(1)
- hdu1247-trie树
- HDU.1233 还是畅通工程(Prim)
- linux中poll,epoll,select区别,等等
- Android 自定义控件基础 canvas paint
- 百练 2775:文件结构“图”(递归法)
- Java开发——JavaScript初步学习