Cod sursa(job #24758)

Utilizator andrei_infoMirestean Andrei andrei_info Data 3 martie 2007 15:58:11
Problema Amlei Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.33 kb
//amlei

type conj = array[1..50] of integer;

var f:array[1..2,1..50] of conj;
    n,t,u,nr1,nr2:integer;

function exista(z:conj; unde,nr:integer):boolean;
var i,j:integer;
    k:boolean;
begin
for i:=1 to nr do
        begin
        k:=true;
        for j:=1 to n do
                if f[unde,i,j] <> z[j] then k:=false;
        if k then
                begin
                exista:=true;
                exit;
                end;
        end;
exista:=false;
end;

procedure sort(var z:conj);
var i,j,aux:integer;
begin
for i:=1 to n-1 do
        for j:=i+1 to n do
                if z[i] > z[j] then
                        begin
                        aux:=z[i];
                        z[i]:=z[j];
                        z[j]:=aux;
                        end;
end;

function egal(z1,z2:integer):boolean;
var i:integer;
begin
egal:=true;
for i:=1 to n do
        if f[1][z1][i] <> f[2][z2][i] then
                egal:=false;
end;

function ok:boolean;
var i,j:integer;
    k:boolean;
begin
if nr1 <> nr2 then begin ok:=false; exit; end;
for i:=1 to nr1 do
        begin
        k:=false;
        for j:=1 to nr2 do
                if egal(i,j) then k:=true;
        if not k then begin ok:=false; exit; end;
        end;
ok:=true;
end;


procedure citire;
var i,j:integer;
    aux:conj;
begin
assign(input,'amlei.in'); reset(input);
assign(output,'amlei.out'); rewritE(output);
while not eof do
        begin
        readln(n,t,u);
        nr1:=0; nr2:=0;
        for i:=1 to t do
                begin
                for j:=1 to n do
                        read(aux[j]);
                sort(aux);
                if not exista(aux,1,nr1) then
                        begin
                        nr1:=nr1+1;
                        f[1,nr1]:=aux;
                        end;
                end;
        for i:=1 to u do
                begin
                for j:=1 to n do
                        read(aux[j]);
                sort(aux);
                if not exista(aux,2,nr2) then
                        begin
                        nr2:=nr2+1;
                        f[2,nr2]:=aux;
                        end;
                end;
        if ok then writeln('DA') else writeln('NU');
        end;
closE(input); close(output);
end;

begin
citire;
end.