| 记录编号 | 18482 | 评测结果 | AAAAAAAAAA | 
    
        | 题目名称 | 462.关键子工程 | 最终得分 | 100 | 
    
        | 用户昵称 |  苏轼 | 是否通过 | 通过 | 
    
        | 代码语言 | Pascal | 运行时间 | 0.099 s | 
    
        | 提交时间 | 2010-09-15 13:29:03 | 内存使用 | 0.00 MiB | 
    
    
    
    		显示代码纯文本
		
		program project(input,output);
var
  i,j,k,n,a,tmp,max:integer;
  ru,chu,t,e,l:array[0..200]of integer;
  way:array[0..200,0..200]of boolean;
  boo:array[0..200]of boolean;
begin
  assign(input,'project.in');
  reset(input);
  assign(output,'project.out');
  rewrite(output);
  readln(n);
  for i:=1 to n do
    read(t[i]);
  for i:=1 to n do
    for j:=1 to n do
      if i<>j then
      begin
        read(a);
        way[j,i]:=(a=1);
        if a=1 then
        begin
          inc(ru[i]);
          inc(chu[j]);
        end;
      end;
  a:=0;
  for i:=1 to n do
    for j:=1 to n do
      if not(boo[j])and(ru[j]=0) then
      begin
        inc(a);
        tmp:=0;
        boo[j]:=true;
        for k:=1 to n do
        begin
          if (ru[k]>0)and(way[j,k]) then
            dec(ru[k]);
          if way[k,j] and (e[k]>tmp) then
            tmp:=e[k];
        end;
        e[j]:=tmp+t[j];
        if e[j]>e[max] then
          max:=j;
      end;
  if a=n then
  begin
  for i:=1 to n do
    for j:=1 to n do
      if boo[j] and(chu[j]=0) then
      begin
        tmp:=maxint;
        boo[j]:=false;
        for k:=1 to n do
        begin
          if (chu[k]>0)and(way[k,j]) then
            dec(chu[k]);
          if way[j,k] and (l[k]-t[k]<tmp) then
            tmp:=l[k]-t[k];
        end;
        if tmp=maxint then
          tmp:=e[max];
        l[j]:=tmp;
      end;
  writeln(e[max]);
  for i:=1 to n do
    if e[i]=l[i] then
      write(i,' ');
  writeln;
  end
  else
    writeln(-1);
  close(input);
  close(output);
end.