Poj 3259 Wormholes判断负权回路(spfa模板题)
来源:互联网 发布:熊孩子洗琴 知乎 编辑:程序博客网 时间:2024/06/05 08:17
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 to F (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.
---------------------------------------------------------------------分割线-------------------------------------------------------------------------------------
朴素的SPFA,判断有无负权回路即可。注意普通道路是无向的。完美的打一遍模板,AK。
var t:boolean; f,i,n:longint; way:array[1..500,1..500] of longint;function min(a,b:longint):longint;begin if a<=b then exit(a) else exit(b);end;procedure Readin;var i,j,si,ei,ti,m,w:longint;begin read(n,m,w); for i:=1 to n do for j:=1 to n do way[i,j]:=maxlongint; for i:=1 to m+w do beginread(si,ei,ti);if i>m then ti:=-ti;way[si,ei]:=min(ti,way[si,ei]);if i<=m then way[ei,si]:=way[si,ei]; end;end;procedure SPFA;var time,dis:array [1..500] of longint; used:array[1..500] of boolean; que:array[1..1000000] of longint; head,tail,i,x:longint;begin t:=false; dis[1]:=0;for i:=2 to n do dis[i]:=maxlongint; fillchar(used,sizeof(used),false); fillchar(time,sizeof(time),0); head:=1;tail:=1;que[1]:=1;time[1]:=1; while head<=tail do begin x:=que[head];for i:=1 to n do if (way[x,i]<>maxlongint) and (dis[i]>dis[x]+way[x,i]) then begin dis[i]:=dis[x]+way[x,i];if not used[i] then begin if time[i]+1>n then begin t:=true;break; end; inc(time[i]); inc(tail); que[tail]:=i;end; end;used[head]:=false;inc(head); end;end;procedure Print;begin if t then writeln('YES') else writeln('NO');end;begin read(f); for i:=1 to f do beginReadin;SPFA;Print; end;end.
- Poj 3259 Wormholes判断负权回路(spfa模板题)
- poj 3259 Wormholes (SPFA 判断有无负权回路)
- POJ 3259Wormholes(SPFA算法判断负权回路)
- POJ 3259 Wormholes(判断负权回路|SPFA||Bellman-Ford)
- POJ 3259 Wormholes SPFA 判断负权回路
- Poj 3259 Wormholes【SPFA判断负权回路】
- POJ_3259(Wormholes)(SPFA判断负权回路)
- POJ 3259 Wormholes 邻接表的SPFA判断负权回路
- POJ 3259 SPFA判断负权回路
- POJ:3259 Wormholes(SPFA判断负环)
- POJ 3259 Wormholes 【SPFA 判断负环】
- poj 3259 Wormholes 【SPFA&&判断负环】
- Poj 3259 Wormholes【spfa 负环判断】
- POJ 3259 Wormholes SPFA 判断负环
- 【POJ 3259】Wormholes (SPFA 判断负环)
- POJ3259 Wormholes(spfa判断负环模板题)
- POJ - 3259 Wormholes(判断负环, Bellman Ford,SPFA)
- POJ 3259 Wormholes 判断负环(spfa)
- Uva442 Matrix Chain Multiplication【stack】【例题6-3】
- 数组初始化问题
- bzoj1060 [ZJOI2007]时态同步 [树形dp][贪心…]
- 一道三角函数相关级数求和问题
- 反射简单的应用
- Poj 3259 Wormholes判断负权回路(spfa模板题)
- SQL 学习笔记_插入删除
- VR系列——Oculus Audio sdk文档:二、Oculus音频SDK指南(4~5)——声音传播时长及缺陷和解决办法
- 我的服务器开发之路-安装vsftpd
- 数据库练习
- java中集合详解
- VMWare虚拟机的桥接、nat、主机模式的区别
- 51nod-1010 只包含因子2 3 5的数
- 个人博客---简要总结(三)