Pagini recente » Cod sursa (job #1361255) | Cod sursa (job #1333631) | Cod sursa (job #1400016) | Profil NaritaandreiCNAI | Cod sursa (job #33749)
Cod sursa(job #33749)
#include <cstdio>
#include <algorithm>
using namespace std;
const char iname[] = "amlei.in";
const char oname[] = "amlei.out";
#define MAX_N 50
#define MAX_T 500
int n, nt, nu;
struct entry {
int a[MAX_N];
} ;
entry t[MAX_T], u[MAX_T];
int thesame(entry e[], int i, int j) {
for (int k = 0; k < n; ++ k)
if (e[i].a[k] != e[j].a[k]) return 0;
return 1;
}
int cmp(entry z, entry w) {
for (int i = 0; i < n; ++ i)
if (z.a[i] != w.a[i]) return z.a[i] < w.a[i];
return 1;
}
int main(void)
{
freopen(iname, "r", stdin);
freopen(oname, "w", stdout);
while (scanf("%d %d %d", & n, & nt, & nu) == 3) {
int i;
int j;
for (i = 0; i < nt; ++ i) {
for (j = 0; j < n; ++ j) scanf("%d", & t[i].a[j]);
sort(t[i].a, t[i].a + n);
}
sort(t, t + nt, cmp);
for (i = 0; i < nu; ++ i) {
for (j = 0; j < n; ++ j) scanf("%d", & u[i].a[j]);
sort(u[i].a, u[i].a + n);
}
sort(u, u + nu, cmp);
int Res = 1;
for (i = j = 0; i < nt && j < nu; ) {
if (i < nt - 1 && thesame(t, i, i + 1)) {
i ++;
continue ;
}
if (j < nu - 1 && thesame(u, j, j + 1)) {
j ++;
continue ;
}
for (int k = 0; k < n; ++ k)
if (t[i].a[k] != u[j].a[k]) Res = 0;
i ++, j ++;
}
if (i < nt || j < nu)
Res = 0;
if (Res)
printf("DA\n");
else
printf("NU\n");
}
return 0;
}