pascal按照标程抄了一遍不知道哪里错了,Runtim
var
 n,m,i,j,x,a,ansd,flag:longint;
 s,h,ans:array[0..1100]of longint;
 u,d,l,r,row,col:array[0..110000]of longint;

procedure init;
var
 i:longint;
begin
 for i:=1 to n do h[i]:=-1;
 for i:=0 to m do
 begin
  s[i]:=0;
  u[i]:=i;
  d[i]:=i;
  l[i]:=i-1;
  r[i]:=i+1
 end;
 l[0]:=m;
 r[m]:=0;
 a:=m
end;

procedure link(x,y:longint);
begin
 inc(a);
 row[a]:=x;
 col[a]:=y;
 inc(s[y]);
 d[a]:=d[y];
 u[d[y]]:=a;
 u[a]:=y;
 d[y]:=a;
 if h[x]<0 then
  begin
   h[x]:=a;
   l[a]:=a;
   r[a]:=a
  end
 else
  begin
   r[a]:=r[h[x]];
   l[r[h[x]]]:=a;
   l[a]:=h[x];
   r[h[x]]:=a
  end
end;

procedure remove(c:longint);
var
 i,j:longint;
begin
 l[r[c]]:=l[c];
 r[l[c]]:=r[c];
 i:=d[c]; while i<>c do begin
 j:=r[i]; while i<>j do begin
 u[d[j]]:=u[j];
 d[u[j]]:=d[j]; dec(s[col[j]]);
 j:=r[j] end;
 i:=d[i] end
end;

procedure resume(c:longint);
var
 i,j:longint;
begin
 i:=u[c]; while i<>c do begin
 j:=l[i]; while i<>j do begin
 d[u[j]]:=j;
 u[d[j]]:=j; inc(s[col[j]]);
 j:=l[j] end;
 i:=u[i] end;
 l[r[c]]:=c;
 r[l[c]]:=c
end;

procedure sk(k:longint);
var
 c,i,j:longint;
begin
 if r[0]=0 then
 begin ansd:=k; flag:=1; exit end;
 c:=r[0];
 i:=c;
 while i<>0 do
 begin
  if s[i]<s[c] then c:=i;
  i:=r[i]
 end;
 remove(c);
 i:=d[c];
 while i<>c do
 begin
  ans[k]:=row[i];
  j:=r[i]; while j<>i do begin remove(col[j]); j:=r[j] end;
  sk(k+1);
  if flag=1 then exit;
  j:=l[i]; while j<>i do begin resume(col[j]); j:=l[j] end;
  i:=d[i]
 end;
 resume(c)
end;

begin
// assign(input,'1017.in'); reset(input);
// assign(output,'1017.out'); rewrite(output);
 read(n,m);
 while n>0 do
 begin
  init;
  for i:=1 to n do
  begin
   read(j);
   for j:=1 to j do
   begin
    read(x);
    link(i,x)
   end
  end;
  flag:=0;
  sk(1);
  if flag=1 then
   begin
    write(ansd-1);
    for i:=1 to ansd-1 do write(' ',ans[i]);
    writeln
   end
  else
   writeln('NO');
  read(n,m)
 end;
// close(input); close(output)
end.
RE是哪里有问题啊。感觉基本一样了吧
© 2015 HUST ACMICPC TEAM. All Right Reserved.