[USACO14OPEN]GPS的决斗Dueling GPS's

题目描述

给你一个N个点的有向图,可能有重边.

有两个GPS定位系统,分别认为经过边i的时间为Pi,和Qi.

每走一条边的时候,如果一个系统认为走的这条边不是它认为的最短路,就会受到警告一次T T

两个系统是分开警告的,就是说当走的这条边都不在两个系统认为的最短路范围内,就会受到2次警告.

如果边(u,v)不在u到n的最短路径上,这条边就受到一次警告,求从1到n最少受到多少次警告。

输入输出格式

输入格式:
Line 1: The integers N and M.
Line i describes road i with four integers: A_i B_i P_i Q_i.

输出格式:
Line 1: The minimum total number of complaints FJ can receive if he routes himself from his house to the farm optimally.
输入输出样例

输入样例#1: 复制
5 7
3 4 7 1
1 3 2 20
1 4 17 18
4 5 25 3
1 2 10 1
3 5 4 14
2 4 6 5
输出样例#1: 复制
1
说明

program df;
type point=^node;
node=record
date,ends,d1,d2:longint;
next:point;
end;
ccdd=record
x,y,z:longint;
end;
var i,j,n,m,x,y,z,k,t:longint;
path,pa,p:array[0..100000] of point;
ans:array[0..100000] of ccdd;
a,c,dis,des,d,g:array[0..100000] of longint;
tm:array[0..1000000] of longint;
b:array[0..100000] of boolean;
procedure com(x,y,z:longint);
var i:point;
begin
i:=path[x];
new(path[x]);
path[x]^.ends:=y;
path[x]^.date:=z;
path[x]^.next:=i;
end;

procedure com2(x,y,z:longint);
var i:point;
begin
i:=pa[x];
new(pa[x]);
pa[x]^.ends:=y;
pa[x]^.date:=z;
pa[x]^.next:=i;
end;

procedure com3(x,y,z1,z2:longint);
var i:point;
begin
i:=p[x];
new(p[x]);
p[x]^.ends:=y;
p[x]^.d1:=z1;
p[x]^.d2:=z2;
p[x]^.next:=i;
end;

procedure spfa(x:longint);
var i:point;
h,t,y,u:longint;
begin
fillchar(dis,sizeof(dis),$6f);
fillchar(b,sizeof(b),false);
h:=0; t:=1; tm[1]:=x; dis[x]:=0;
repeat
inc(h);
u:=tm[h];
i:=path[u];
b[u]:=false;
while i<>nil do
begin
y:=i^.ends;
if dis[y]>dis[u]+i^.date then
begin
dis[y]:=dis[u]+i^.date;
d[y]:=u;
if not b[y] then
begin
inc(t);
tm[t]:=y;
b[y]:=true;
end;
end;
i:=i^.next;
end;
until h=t;
end;

procedure spfa2(x:longint);
var i:point;
h,t,y,u:longint;
begin
fillchar(des,sizeof(des),$6f);
fillchar(b,sizeof(b),false);
h:=0; t:=1; tm[1]:=x; des[x]:=0;
repeat
inc(h);
u:=tm[h];
i:=pa[u];
b[u]:=false;
while i<>nil do
begin
y:=i^.ends;
if des[y]>des[u]+i^.date then
begin
des[y]:=des[u]+i^.date;
g[y]:=u;
if not b[y] then
begin
inc(t);
tm[t]:=y;
b[y]:=true;
end;
end;
i:=i^.next;
end;
until h=t;
end;

procedure spd(x:longint);
var i:point;
h,t,y,u,zz:longint;
begin
fillchar(b,sizeof(b),false);
fillchar(ans,sizeof(ans),$7f);
h:=0; t:=1; ans[x].x:=0; ans[x].y:=0; ans[x].z:=0; tm[1]:=x;
repeat
inc(h);
u:=tm[h];
i:=p[u];
while i<>nil do
begin
y:=i^.ends;
zz:=0;
if i^.d1>dis[u]-dis[y] then inc(zz);
if i^.d2>des[u]-des[y] then inc(zz);
if ans[y].z>ans[u].z+zz then
begin
ans[y].z:=ans[u].z+zz;
ans[y].x:=ans[u].x+i^.d1;
ans[y].y:=ans[u].y+i^.d2;
if not b[y] then
begin
inc(t);
tm[t]:=y;
b[y]:=true;
end;
end;
i:=i^.next;
end;
until h=t;
end;

begin
readln(n,m);
for i:=1 to m do
begin
read(x,y,z);
com(y,x,z);
t:=z;
readln(z);
com2(y,x,z);
com3(x,y,t,z);
end;
spfa(n);
spfa2(n);

spd(1);
writeln(ans[n].z);
end.

posted @ 2017-10-28 19:19  Gxyhqzt  阅读(299)  评论(0编辑  收藏  举报