记录编号 83313 评测结果 AAAAAAAAAA
题目名称 [NOIP 2013]车站分级 最终得分 100
用户昵称 GravatarPeter Bee 是否通过 通过
代码语言 Pascal 运行时间 0.649 s
提交时间 2013-12-02 17:26:32 内存使用 1.13 MiB
显示代码纯文本
program level2013;
var ans,i,j,k,l,m,n,t,r:integer;
    w:array[0..1000,0..1000]of boolean;
    s,into,q:array[0..1000]of integer;
    finish:boolean;

begin
 assign(input,'level2013.in');reset(input);
 assign(output,'level2013.out');rewrite(output);
  readln(n,m);
  for i:=1 to m do begin
  read(t);
  for j:=1 to t do read(s[j]);
  for j:=1 to t do begin
  if j<>1 then for k:=s[j-1]+1 to s[j]-1 do
  for l:=1 to t do if not w[k,s[l]] then begin
  w[k,s[l]]:=true;
  inc(into[s[l]]);
  end;
  end;
  readln;
  end;

  while not finish do begin
  finish:=true;
  inc(ans);
  fillchar(q,sizeof(q),0);
  r:=0;
  for i:=1 to n do if into[i]=0 then begin into[i]:=-1;q[r]:=i;inc(r);end;
  for i:=0 to r-1 do
  for j:=1 to n do if w[q[i],j] then begin
  finish:=false;
  dec(into[j]);
  end;
  end;

  writeln(ans);
  close(input);
  close(output);
end.