Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 CCC-2003-S5 help!
Index -> Contests
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jimjim168




PostPosted: Tue Feb 16, 2010 11:01 pm   Post subject: CCC-2003-S5 help!

I've been solving the problem CCC-2003-S5 and always got a zero as a result...
Following is my Pascal code, could anyone tell me where is wrong?
Tks.

Quote:

program CCC_2003_s5l;

uses math;

var i,xx,yy,ww,cities,roads,dests,max_weight,now_node,sign,max:longint;
map:array[0..1000,0..1000] of longint;
visited:array[0..1000] of boolean;
weight,mubiao:array[0..1000] of longint;

procedure swap(var pa,pb:longint);
var tmp:longint;
begin
tmp:=pa;
pa:=pb;
pb:=tmp;
end;

begin
assign(input,'s5.in');
reset(input);
readln(cities,roads,dests);
for i:=1 to roads do
begin
readln(xx,yy,ww);
if xx>yy then swap(xx,yy);
if ww>map[xx,yy] then
begin
map[xx,yy]:=ww;
map[yy,xx]:=ww;
end;
end;
fillchar(mubiao,sizeof(mubiao),false);
for i:=1 to dests do
readln(mubiao[i]);
fillchar(weight,sizeof(weight),0);

weight[1]:=maxlongint;
now_node:=1;

repeat
sign:=now_node;
visited[now_node]:=true;
now_node:=-1;
max:=0;
for i:=1 to cities do
begin
if (min(weight[sign],map[sign,i])>weight[i]) then
weight[i]:=min(weight[sign],map[sign,i]);
if (weight[i]>=max) and not visited[i] then
begin
max:=weight[i];
now_node:=i;
end;
end;
weight[now_node]:=max_weight;
until now_node=-1;

max:=maxlongint;
for i:=1 to dests do
if weight[mubiao[i]]<max then max:=weight[mubiao[i]];
writeln(max);
end.
Sponsor
Sponsor
Sponsor
sponsor
A.J




PostPosted: Tue Feb 16, 2010 11:05 pm   Post subject: RE:CCC-2003-S5 help!

Er...mind telling us a bit more about your program, what algorithm it is implementing, any debugging you have done so far, etc...

Try fixing this yourself first, then if you can't seem to get it working, tell us what you encountered so far and then ask us for help.
jimjim168




PostPosted: Tue Feb 16, 2010 11:13 pm   Post subject: Re: RE:CCC-2003-S5 help!

A.J @ 2010-02-17, 12:05 pm wrote:
Er...mind telling us a bit more about your program, what algorithm it is implementing, any debugging you have done so far, etc...

Try fixing this yourself first, then if you can't seem to get it working, tell us what you encountered so far and then ask us for help.


Um... Maybe... I guess something's wrong with my algorithm when using the Prim's algorithm to get the MST...
I ain't quite familiar with this part...
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: