记录编号 |
18674 |
评测结果 |
AAAAAAAAAA |
题目名称 |
关键子工程 |
最终得分 |
100 |
用户昵称 |
Des. |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.078 s |
提交时间 |
2010-09-17 13:57:18 |
内存使用 |
0.27 MiB |
显示代码纯文本
program project;
var a,b:array[1..200,0..200]of integer;
l,f,q,an,ex:array[1..200]of longint;
t,k,m,n,i,j,max,oo:longint;
p:boolean;
procedure topo(i:longint);
var t,k:longint;
begin
if i=n+1 then p:=true;
for t:=1 to n do
if (b[t,0]=0)and(ex[t]=0) then
begin
for k:=1 to n do
if b[k,t]=1 then
begin
b[k,t]:=-1;
dec(b[k,0]);
end;
q[i]:=t;
ex[t]:=1;
topo(i+1);
exit;
end;
end;
procedure sou(i,s:longint);
var t,k:longint;
begin
for t:=i+1 to n do
if (a[q[t],q[i]]=1)and(f[q[t]]=s)and(ex[q[t]]=0) then
begin
inc(oo);
ex[q[t]]:=1;
sou(t,f[q[t]]-l[q[t]]);
end;
end;
begin
assign(input,'project.in');
reset(input);
assign(output,'project.out');
rewrite(output);
readln(n);
for t:=1 to n do
read(l[t]) ;
readln;
for t:=1 to n do
begin
k:=0;
repeat
inc(k);
if t<>k then
begin
read(a[k,t]);
if a[k,t]=1 then inc(a[k,0]);
end;
until k=n;
readln;
end;
b:=a;
p:=false;
for t:=1 to n do
if b[t,0]=0 then
begin
for k:=1 to n do
if b[k,t]=1 then
begin
b[k,t]:=-1;
dec(b[k,0]);
end;
q[1]:=t;
ex[q[1]]:=1;
topo(2);
break;
end;
if not p then
begin
writeln(-1);
close(output);
halt;
end;
for t:=n downto 1 do
begin
f[q[t]]:=l[q[t]];
for k:=n downto t+1 do
if (a[q[k],q[t]]=1)and(f[q[k]]+l[q[t]]>f[q[t]]) then
f[q[t]]:=f[q[k]]+l[q[t]];
if f[q[t]]>max then
begin
max:=f[q[t]];
j:=t;
end;
end;
writeln(max);
fillchar(ex,sizeof(ex),0);
for t:=n downto 1 do
begin
if (f[q[t]]=max) then
begin
ex[q[t]]:=1;
sou(t,max-l[q[t]]);
end;
end;
for t:=1 to n do
if ex[t]=1 then
write(t,' ');
close(input);
close(output);
end.