POJ 3259 Wormholes (bellman_ford)
来源:互联网 发布:mysql exists 代替 in 编辑:程序博客网 时间:2024/05/18 20:48
题目链接:~( ̄▽ ̄~)(~ ̄▽ ̄)~
资料链接:\(▔▽▔)/
code:
#include <stdio.h>int n = 0, m = 0, w = 0, count = 0;typedef struct{int u, v, weight;}node;node edge[6000];int bellman_ford(){int i = 0, j = 0, dis[505], u = 0, v = 0, weight = 0, flag = 0;for(i = 0; i<=n; i++)dis[i] = 1234567890;dis[1] = 0;for(i = 0; i<n-1; i++)//循环时循环n-1个点,应为每次最少找出1条最短边,共有n-1条边{flag = 1;for(j = 0; j<count; j++){u = edge[j].u; v = edge[j].v; weight = edge[j].weight;if(dis[v]>dis[u]+weight){dis[v] = dis[u]+weight;flag = 0;}}if(flag)break;}for(i = 0; i<count; i++)//有负权回路时会无限循环{u = edge[i].u; v = edge[i].v; weight = edge[i].weight;if(dis[v]>dis[u]+weight)return 1;}return 0;}int main(){int i = 0, t = 0,s = 0, e = 0, text = 0;scanf("%d",&text);while(text--){count = 0;scanf("%d %d %d",&n,&m,&w);for(i = 0; i<m; i++){scanf("%d %d %d",&s, &e, &t);edge[count].u = s;edge[count].v = e;edge[count++].weight = t;edge[count].v = s;edge[count].u = e;edge[count++].weight = t;}for(i = 0; i<w; i++){scanf("%d %d %d",&s,&e,&t);edge[count].u = s;edge[count].v = e;edge[count++].weight = -t;}if(bellman_ford())printf("YES\n");elseprintf("NO\n");}return 0;}
- POJ 3259 Wormholes (bellman_ford)
- POJ 3259 Wormholes (Bellman_Ford)
- POJ 3259 Wormholes bellman_ford
- poj 3259 Wormholes (bellman_ford)
- POJ 3259 Wormholes(最短路Bellman_Ford)
- POJ 3259 Wormholes (bellman_ford算法判负环)
- POJ 3259 Wormholes(Bellman_Ford判负圈)
- poj 3259 Wormholes[ bellman_ford 判负环]
- Poj 3259 Wormholes(bellman_ford判负环)
- POJ-3259 Wormholes (bellman_ford算法)
- 【POJ 3259】Wormholes(最短路SPFA/Bellman_Ford)
- (POJ 3259)Wormholes 判断负环 bellman_ford 或者 spfa
- POJ 3259:Wormholes:bellman_ford算法判负环
- Wormholes (poj 3259 SPFA || Bellman_Ford 判负环)
- POJ 3259:Wormholes bellman_ford判定负环
- poj Wormholes最短路问题(bellman_ford)
- poj Wormholes(Bellman_ford寻找负权环)
- Poj 3259(bellman_ford)
- Linux/Unix中的基本系统数据类型
- 第七周任务(二)
- 将数组划分为两个元素和最接近的子数组
- 第七周作业3
- 第7周实验报告2
- POJ 3259 Wormholes (bellman_ford)
- 第七周任务(三)
- 第七周实验报告1
- flex meun 使用
- Process Resources
- hdoj 3667 Transportation
- Fedora14下编译qtopia问题
- [设计模式]Strategy Pattern(策略模式).(1)
- 整理了独立博客大全导航地址分享给大家