记录编号 138112 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 月考统计 最终得分 100
用户昵称 Gravatar东方老败 是否通过 通过
代码语言 Pascal 运行时间 1.384 s
提交时间 2014-11-05 17:45:37 内存使用 0.17 MiB
显示代码纯文本
const e=1013;
type point=^note;
     note=record
	   da,va:longint;
	   ne:point;
	   end;
var n,m,i,j,k,o1,o2,o3,he,ta:longint;
    a:array[0..1000]of note;
	q,d:array[0..1013]of longint;
	bo:array[0..1000]of boolean;
        tak:array[0..1000]of longint;//入队列次数
	p,u,v:point;

procedure add_edge(x,y,z:longint);
begin
new(p);
p^.da:=y;
p^.va:=z;
p^.ne:=a[x].ne;
a[x].ne:=p;
inc(a[x].da);
end;

procedure init;
begin
readln(n,m);
for i:=1 to m do
begin
 readln(o1,o2,o3);
 add_edge(o1,o2,-o3);
end;
for i:=1 to n do  add_edge(0,i,0);
end;

procedure work;
begin
for i:=1 to n do d[i]:=-maxlongint div 3;
he:=0;ta:=1;q[1]:=0;bo[0]:=true;tak[0]:=1;
while he<>ta do
begin
 he:=(he+1)mod e;
 o1:=q[he];
 u:=a[o1].ne;
 bo[o1]:=false;
 for i:=1 to a[o1].da do
 begin
  if d[o1]+u^.va>d[u^.da] then
  begin
   d[u^.da]:=d[o1]+u^.va;
   if not bo[u^.da] then
   begin
    ta:=(ta+1)mod e;
	q[ta]:=u^.da;
	inc(tak[u^.da]);
	bo[u^.da]:=true;
	if tak[u^.da]>n then
	 begin writeln('SOMEONE LAY!');exit;end;
   end;
  end;
  u:=u^.ne;
 end;
end;
for i:=1 to n do
if d[i]<>-maxlongint div 3 then write(d[i],' ')
else write(-1,' ');
end;
	
begin
assign(input,'ExamStat.in');reset(input);
assign(output,'ExamStat.out');rewrite(output);
init;
work;
close(output);
end.