Cod sursa(job #12484)

Utilizator andreitheo87Teodorescu Andrei-Marius andreitheo87 Data 4 februarie 2007 03:09:18
Problema Aprindere Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.64 kb
var fi,fo:text;
    n,m,i,j,x:integer;
    rez:longint;
    mat:array[0..1000,0..100]of integer;
    c,st:array[0..1000]of integer;
begin
 assign(fi,'aprindere.in'); reset(fi);
 assign(fo,'aprindere.out'); rewrite(fo);
 readln(fi,n,m);
 for i:=0 to n-1 do read(fi,st[i]);
 for i:=1 to m do
  begin
        read(fi,x); read(fi,c[x]);
        read(fi,mat[x][0]);
        for j:=1 to mat[x][0] do
         read(fi,mat[x][j]);
  end;
 rez:=0;
 for i:=0 to n-1 do
  if st[i]=0 then
   begin
         rez:=rez+c[i];
         for j:=1 to mat[i][0]do
          st[mat[i][j]]:=1-st[mat[i][j]];
   end;
 writeln(fo,rez);
 close(fo);
end.