Wormholes(负权回路)
来源:互联网 发布:奥地利 知乎 编辑:程序博客网 时间:2024/05/18 02:48
While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ's farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1..N,M (1 ≤M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes.
As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure. Perhaps he will be able to meet himself :) .
To help FJ find out whether this is possible or not, he will supply you with complete maps toF (1 ≤F ≤ 5) of his farms. No paths will take longer than 10,000 seconds to travel and no wormhole can bring FJ back in time by more than 10,000 seconds.
23 3 11 2 21 3 42 3 13 1 33 2 11 2 32 3 43 1 8
NOYES
#if 0#include<iostream>#include<cstring>using namespace std;int n,m,no,k; //点,路,黑洞 struct lu{int a,b,t;}mapp[10000];int dis[10000]; void ford_one(){memset(dis,0x7f,sizeof(dis));dis[1]=0; int a,b,t;for(int i=1; i<=n-1; i++){bool flag=0;for(int j=1; j<=k; j++){a=mapp[j].a; b=mapp[j].b;t=mapp[j].t;if(dis[b]>dis[a]+mapp[j].t){dis[b]=dis[a]+mapp[j].t;flag=1;}}if(flag==0)break;}}int ford_two(){int a,b,t; for(int j=1; j<=k; j++){a=mapp[j].a; b=mapp[j].b;t=mapp[j].t;if(dis[b]>dis[a]+mapp[j].t)return 1;}return 0;}int main(){int T;cin>>T;while(T--){cin>>n>>m>>no; k=0;for(int i=1; i<=m; i++) {int aa,bb,xx;cin>>aa>>bb>>xx;k++;mapp[k].a=aa;mapp[k].b=bb;mapp[k].t=xx;k+=1;mapp[k].a=bb;mapp[k].b=aa;mapp[k].t=xx;}for(int i=1; i<=no; i++){int aa,bb,xx;cin>>aa>>bb>>xx;k+=1;mapp[k].a=aa;mapp[k].b=bb;mapp[k].t=-xx; }ford_one();if(ford_two()){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}}#endif
- Wormholes(负权回路)
- poj 3259 Wormholes (SPFA 判断有无负权回路)
- POJ 3259Wormholes(SPFA算法判断负权回路)
- POJ-3259 Wormholes(负权回路[Bellman-Ford])
- POJ 3259 Wormholes (Bellman) (负权回路)
- POJ 3259 Wormholes (寻找负权回路)
- TOJ 1661 Wormholes -- 负权回路 Dijkstra
- POJ_3259(Wormholes)(SPFA判断负权回路)
- [ACM] POJ 3259 Wormholes (bellman-ford最短路径,判断是否存在负权回路)
- Poj 3259 Wormholes判断负权回路(spfa模板题)
- PKU 3259 Wormholes - 判断负权回路 Bellman-Ford
- POJ 3259 Wormholes(判断负权回路|SPFA||Bellman-Ford)
- poj3259 Wormholes 图的负权回路判定,Bellman_Ford
- POJ 3259 Wormholes SPFA 判断负权回路
- Poj 3259 Wormholes【SPFA判断负权回路】
- UVa 558 - Wormholes (求负回路)
- poj3259 Wormholes(bellman负权处理)
- Wormholes(负圈)
- 短信在Mms中处理流程
- 局域网中连接mysql数据库
- SQL NOT NULL 约束
- Bridging signals
- JZOJ 5132 子序列
- Wormholes(负权回路)
- 最小生成树( Highways + Agri-Net)
- Peter的烟
- A+B problem
- 2-6使用ACL访问控制列表对文件的访问
- 2017.6.4测试 题七 K上升段
- 常见的排序算法C语言实现(—)
- 理解Linux文件权限
- find the mincost route(城市最小环)