比赛 |
2008haoi模拟训练1 |
评测结果 |
AAATTTTTTT |
题目名称 |
水管局长 |
最终得分 |
30 |
用户昵称 |
梦里醉逍遥 |
运行时间 |
21.262 s |
代码语言 |
Pascal |
内存使用 |
13.93 MiB |
提交时间 |
2008-04-22 09:48:18 |
显示代码纯文本
program tube;
const
fi='tube.in'; fo='tube.out';
maxn=1000; maxm=200000; maxq=2000000;
type
node=record
b,g,w:longint;
end;
arr1=array[1..maxm] of node;
arr2=array[1..maxn,1..maxn] of longint;
arr3=array[1..maxn] of longint;
arr4=array[1..maxq] of longint;
var
fin,fout:text; n,m,q,head,tail:longint;
s:arr1; v:arr2; mark,hash:arr3; queue:arr4;
function max(i,j:longint):longint;
begin
if i>j then max:=i
else max:=j;
end;
procedure swap(var i,j:node);
var
tmp:node;
begin
tmp:=i; i:=j; j:=tmp;
end;
procedure qsort(i,j:longint);
var
l,r,mid:longint;
begin
l:=i; r:=j; mid:=s[(i+j) shr 1].b;
repeat
while s[l].b<mid do l:=l+1;
while s[r].b>mid do r:=r-1;
if l<=r then begin
swap(s[l],s[r]);
l:=l+1; r:=r-1;
end;
until l>r;
if r>i then qsort(i,r);
if j>l then qsort(l,j);
end;
procedure init;
var
i,j,k:longint;
begin
assign(fin,fi); reset(fin);
assign(fout,fo); rewrite(fout);
readln(fin,n,m,q);
for i:=1 to m do begin
readln(fin,s[i].b,s[i].g,s[i].w);
s[m+i].b:=s[i].g;
s[m+i].g:=s[i].b;
s[m+i].w:=s[i].w;
end;
m:=m*2;
for i:=1 to n do
for j:=1 to n do
v[i,j]:=maxlongint;
qsort(1,m);
fillchar(mark,sizeof(mark),0);
fillchar(queue,sizeof(queue),0);
j:=s[1].b; mark[j]:=1;
for i:=2 to m do
if s[i].b<>j then begin
j:=s[i].b;
mark[j]:=i;
end;
end;
procedure insert(x:longint);
begin
tail:=tail+1;
queue[tail]:=x;
hash[x]:=1;
end;
procedure delete;
begin
hash[queue[head]]:=0;
head:=head+1;
end;
procedure spfa(x,y:longint);
var
i,j,k:longint;
begin
head:=1; tail:=0;
insert(x); v[x,x]:=0;
while head<=tail do begin
i:=queue[head]; j:=mark[i];
while s[j].b=i do begin
k:=max(v[x,i],s[j].w);
if k<v[x,s[j].g] then begin
v[x,s[j].g]:=k;
if hash[s[j].g]=0 then insert(s[j].g);
end;
j:=j+1;
end;
delete;
end;
end;
procedure get(x,y:longint);
var
i:longint;
begin
i:=mark[x];
while s[i].b=x do begin
if s[i].g=y then begin
s[i].w:=maxlongint;
exit;
end;
i:=i+1;
end;
end;
procedure main;
var
i,j,k,l,p:longint;
begin
for i:=1 to q do begin
read(fin,j);
case j of
1:begin
readln(fin,k,l);
if v[k,l]=maxlongint then
spfa(k,l);
writeln(fout,v[k,l]);
end;
2:begin
readln(fin,k,l);
get(k,l); get(l,k);
for k:=1 to n do
for l:=1 to n do
v[k,l]:=maxlongint;
end;
end;
end;
close(fin); close(fout);
end;
begin
init;
main;
end.