| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大牛指教。。。WA求错误program POJ1679;
var
n,edge,node,i,j,x,y,dis,ans,secans,temp,tot:longint;
a,tedge:array [0..500,0..500] of longint;
b:array [0..500] of boolean;
v,rec:array [0..500] of longint;
function prim:longint;
var
ii,jj,min,net:longint;
begin
tot:=0;
prim:=0;
v[1]:=0;
for ii:=1 to node do
begin
min:=maxlongint;
for jj:=1 to node do
begin
if (v[jj]<min) and (not b[jj]) then
begin
min:=v[jj];
net:=jj;
end;
end;
inc(tot);
rec[tot]:=net;
b[net]:=true;
inc(prim,min);
for jj:=1 to node do
begin
if (a[net,jj]<v[jj]) and (not b[jj]) then v[jj]:=a[net,jj];
end;
end;
exit(prim);
end;
function prim_x:longint;
var
ii,jj,min,net:longint;
begin
prim_x:=0;
v[1]:=0;
for ii:=1 to node do
begin
min:=maxlongint;
for jj:=1 to node do
begin
if (v[jj]<min) and (not b[jj]) then
begin
min:=v[jj];
net:=jj;
end;
end;
b[net]:=true;
inc(prim_x,min);
for jj:=1 to node do
begin
if (a[net,jj]<v[jj]) and (not b[jj]) then v[jj]:=a[net,jj];
end;
end;
exit(prim_x);
end;
begin
assign(input,'c:\in.txt'); reset(input);
assign(output,'c:\out.txt'); rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(node,edge);
fillchar(a,sizeof(a),100);
for j:=1 to edge do
begin
readln(x,y,dis);
if (dis<a[x,y]) or (a[x,y]=0) then
begin
a[x,y]:=dis;
a[y,x]:=dis;
end;
end;
fillchar(v,sizeof(v),100);
fillchar(b,sizeof(b),false);
fillchar(rec,sizeof(rec),0);
ans:=prim;
for j:=1 to tot-1 do
begin
fillchar(v,sizeof(v),100);
fillchar(b,sizeof(b),false);
temp:=a[rec[j],rec[j+1]];
a[rec[j],rec[j+1]]:=2147483600;
a[rec[j+1],rec[j]]:=2147483600;
secans:=prim_x;
a[rec[j],rec[j+1]]:=temp;
a[rec[j+1],rec[j]]:=temp;
if secans=ans then break;
end;
if secans=ans then writeln('Not Unique!') else writeln(ans);
end;
close(input); close(output);
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator