比赛 |
20120710 |
评测结果 |
AAAAAAEAAE |
题目名称 |
三元限制最短路 |
最终得分 |
80 |
用户昵称 |
fuhao |
运行时间 |
0.149 s |
代码语言 |
Pascal |
内存使用 |
100.40 MiB |
提交时间 |
2012-07-10 11:42:53 |
显示代码纯文本
program patha;
const maxn=3001; maxtot=1000000;
var
pre,xx,yy,step,link,next:array[0..maxtot] of longint;
aa,a:array[0..maxn,0..maxn] of longint;
v:array[0..maxn,0..maxn] of boolean;
n,i,x,y,z,tot,m,k,j,l:longint;
procedure print(k:longint);
begin
if pre[k]=0 then
begin
write(1,' ',yy[k]);
exit;
end;
print(pre[k]);
write(' ',yy[k]);
end;
procedure bfs;
var h,t,i:longint;
begin
h:=0; t:=0;
for i:=1 to n do
if a[1,i]<>0 then
if not v[1,i] then
begin
inc(t);
xx[t]:=1; yy[t]:=i; step[t]:=1;
pre[t]:=0;
v[1,i]:=true;
if yy[t]=n then
begin
writeln(step[t]);
print(t);
close(input); close(output);
halt;
end;
end;
repeat
inc(h);
i:=a[xx[h],yy[h]];
while i<>0 do
begin
if not v[yy[h],link[i]] then
begin
v[yy[h],link[i]]:=true;
inc(t); pre[t]:=h;
xx[t]:=yy[h]; yy[t]:=link[i];
step[t]:=step[h]+1;
if yy[t]=n then
begin
writeln(step[t]);
print(t);
close(input); close(output);
halt;
end;
end;
i:=next[i];
end;
until h=t;
end;
procedure insert(x,y:longint);
begin
inc(aa[x,0]); aa[x,aa[x,0]]:=y;
end;
procedure delete(x,y,z:longint);
var i,fa:longint;
begin
i:=a[x,y];
if link[i]=z then
begin
a[x,y]:=next[i];
exit;
end;
fa:=i;
while i<>0 do
begin
if link[i]=z then
begin
next[fa]:=next[i];
exit;
end;
fa:=i;
i:=next[i];
end;
end;
procedure init(x,y,z:longint);
begin
inc(tot); next[tot]:=a[x,y];
a[x,y]:=tot; link[tot]:=z;
end;
begin
assign(input,'patha.in'); reset(input);
assign(output,'patha.out'); rewrite(output);
readln(n,m,k);
for i:=1 to m do
begin
readln(x,y);
insert(x,y);
insert(y,x);
end;
for i:=1 to n do
for j:=1 to aa[i,0] do
for l:=1 to aa[aa[i,j],0] do
init(i,aa[i,j],aa[aa[i,j],l]);
for i:=1 to k do
begin
readln(x,y,z);
delete(x,y,z);
end;
bfs;
close(input); close(output);
end.