Cod sursa(job #12487)

Utilizator andrei_infoMirestean Andrei andrei_info Data 4 februarie 2007 09:24:50
Problema Aprindere Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.51 kb
//infoarena chernel unirea 2007
type pnod = ^tnod;
     tnod = record
                x:integer;
                next:pnod;
                end;

type cam = record
           are,stare:boolean;
           t :integer;
           head,last:pnod;
           end;

var m,n:longint;
    a:array[0..1000] of cam;

procedure addlist(list,val:integer);
var p:pnod;
begin
new(p); p^.x:=val; p^.next:=nil;
if a[list].head = nil then a[list].head :=p
else a[list].last^.next:=p;
a[list].last:=p;
end;

procedure citire;
var i,j,x,c,t,nr:integer;
begin
assign(input,'aprindere.in'); reset(input);
readln(n,m);
for i:=0 to n-1 do
        begin
        read(x);
        if x =1 then a[i].stare:=true;
        end;
for i:=1 to m do
        begin
        read(c,t,nr);
        a[c].are:=true;
        a[c].t:=t;
        for j:=1 to nr do
                begin
                read(X);
                addlist(c,x);
                end;
        end;
end;

procedure calc;
var i:integer;
    p:pnod;
    rez:longint;
begin
rez:=0;
for i:=0 to n-1 do
        if not a[i].stare then
                begin
                rez:=rez+a[i].t;
                p:=a[i].head;
                while p <> nil do
                        begin
                        a[p^.x].stare:= not a[p^.x].stare;
                        p:=p^.next;
                        end;
                end;
assign(output,'aprindere.out'); rewrite(output);
writeln(rez);
close(output);
end;

begin
citire;
calc;
end.