ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

I got WA !!! Look trought my code and tell me what's wrong in it !!! PLEASE!!! (PROBLEM 1018)
Posted by Romanchik Vitaly 6 Aug 2002 02:39
var a:array[1..100,1..100]of longint;
    n,q:longint;
    b:array[1..10000]of longint;
    c:array[1..10000]of longint;
    noch,koch,i,ch1,ch2,s:longint;
    d:array[1..10000]of longint;
function find:longint;
var i:longint;
    max:longint;
begin
 max:=0;
 while noch<=koch do
  begin
   for i:=1 to n do
    if a[b[noch],i]<>0 then
     begin
      inc(koch);
      b[koch]:=i;
      c[koch]:=c[noch]+a[b[noch],i];
      d[koch]:=d[noch]+1;
      a[b[noch],i]:=0;
      a[i,b[noch]]:=0;
      if (d[koch]=q)and(c[koch]>max)then max:=c[koch];
      if d[koch]>q then break;
     end;
   inc(noch);
  end;
 find:=max;
end;
begin
 readln(n,q);
 for i:=1 to n-1 do
  begin
   readln(ch1,ch2,s);
   a[ch1,ch2]:=s;
   a[ch2,ch1]:=s;
  end;
 noch:=1;koch:=1;
 b[koch]:=1;
 writeln(find);
end.