比赛 20110318 评测结果 AWWWWWWWWE
题目名称 工程规划 最终得分 10
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-03-18 20:58:43
显示代码纯文本
program work;
var
  list,q,dist:array[0..1001] of longint;
  v,w,next:array[0..6000] of longint;
  b:array[0..1001] of boolean;
  n,i,j,h,t,u,num,m,r1,r2,r3,min:longint;
begin
  assign(input,'work.in');
  reset(input);
  assign(output,'work.out');
  rewrite(output);

  readln(n,m);
  fillchar(list,sizeof(list),0);
  fillchar(next,sizeof(next),0);
  fillchar(w,sizeof(w),0);
  num:=0;
  for i:=1 to m do
  begin
    readln(r2,r1,r3);
    inc(num);
    v[num]:=r2;
    w[num]:=r3;
    next[num]:=list[r1];
    list[r1]:=num;
  end;
  for i:=1 to n do
  begin
    inc(num);
    v[num]:=i;
    w[num]:=0;
    next[num]:=list[0];
    list[0]:=num;
  end;

  fillchar(q,sizeof(q),0);
  fillchar(b,sizeof(b),false);
  for i:=1 to n do
    dist[i]:=maxlongint;
  dist[0]:=0;
  h:=0;
  t:=1;
  q[1]:=0;
  b[0]:=true;
  while h<>t do
  begin
    h:=(h+1) mod (n+1);
    i:=q[h];
    u:=list[i];
    while u>0 do
    begin
      j:=v[u];
      if dist[i]+w[u]<dist[j] then
      begin
        dist[j]:=dist[i]+w[u];
        if b[j]=false then
        begin
          t:=(t+1) mod (n+1);
          q[t]:=j;
          b[j]:=true;
        end;
        if dist[j]<-n then
        begin
          writeln('NO SOLUTION');
          close(input);
          close(output);
          halt
        end;
      end;
      u:=next[u];
    end;
    b[i]:=false;
  end;

  min:=0;
  for i:=1 to n do
    if dist[i]<min then min:=dist[i];
  for i:=1 to n do
    writeln(dist[i]-min);

  close(input);
  close(output)
end.