记录编号 124206 评测结果 AAAAAAAAAA
题目名称 [NOIP 2013]车站分级 最终得分 100
用户昵称 Gravatarhelloworld123 是否通过 通过
代码语言 Pascal 运行时间 0.640 s
提交时间 2014-10-02 17:30:46 内存使用 1.13 MiB
显示代码纯文本
program leve2013;
var
 ans,i,j,k,l,m,n,t,r:longint;
 w:array[0..1000,0..1000] of boolean;
 s,a,q:array[0..1000] of longint;
 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(a[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 a[i]=0 then
	   begin
	    a[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(a[j]);
		end;
	end;
	
	writeln(ans);
 close(input); close(output);
end.