Pagini recente » Cod sursa (job #11365) | Cod sursa (job #267074) | Cod sursa (job #2250698) | Cod sursa (job #42) | Cod sursa (job #10944)
Cod sursa(job #10944)
program aprindere;
const
fin='aprindere.in';
fout='aprindere.out';
type
list=^info;
info=record
next:list;
x:longint;
end;
var
bec:array[0..1000] of byte;
switch:array[0..1000] of list;
p,q,aux:list;
ctot:longint;
n,m,i,j,k,x,y:longint;
nr,cost:array[0..1000] of longint;
begin
assign(input,fin);
reset(input);
readln(n,m);
for i:=0 to n-1 do
read(bec[i]);
readln;
for i:=1 to m do
begin
read(x);
new(switch[x]);
switch[x]^.next:=nil;
read(cost[x]);
read(nr[x]);
for j:=1 to nr[x] do
begin
read(y);
new(q);
q^.next:=switch[x]^.next;
q^.x:=y;
switch[x]^.next:=q;
end;
end;
close(input);
assign(output,fout);
rewrite(output);
ctot:=0;
for i:=0 to n-1 do
if bec[i]=0 then
begin
inc(ctot,cost[i]);
q:=switch[i]^.next;
while q<>nil do
begin
x:=q^.x;
bec[x]:=bec[x] xor 1;
q:=q^.next;
end;
end;
writeln(ctot);
close(output);
end.