Logo Universal Online Judge

UOJ

时间限制:1 s 空间限制:64 MB

#1950. Zamjena

统计

题面翻译

Vlatko 喜欢玩整数数组。 他在一张纸上写了两个包含 N 个元素的数组,每个元素要么是一个正整数,要么是代表一个变量的英文字母的小写字母序列。 变量可以替换为任意整数。 两个数组可能包含相同的变量,或者相同的变量在一个数组中出现多次。 如果是这种情况,变量的每次出现都必须在两个数组中替换为相同的整数。

Vlatko 想知道是否可以用一些整数值替换所有变量,从而使两个数组相等。 如果数组中相同位置的数字相等,则认为两个数组相等。

题目描述

Vlatko likes to play with integer arrays. He wrote two arrays of N elements on a piece of paper, each element being either a positive integer or a sequence of lowercase letters of the English alphabet representing a variable. A variable can be replaced with an arbitrary integer. It's possible that both arrays contain the same variable or the same variable occurs multiple times in an array. If that’s the case, each occurence of the variable has to be replaced with the same integer in both arrays.

Vlatko wonders if it's possible to replace all variables with some integer values in such a way that the two arrays become equal. Two arrays are considered equal if the numbers on the same positions in the arrays are equal.

输入格式

The first line contains a positive integer N (1 ≤ N ≤ 50 000), the number of elements in each array.

The second line contains N elements of the first array.

The third line contains N elements of the second array.

Each element in both arrays can either be:

● a positive integer less than 1 000 or

● a sequence of lowercase letters of the English alphabet (no longer than 10 characters) which represents a variable.

第一行包含一个正整数 N (1 ≤ N ≤ 50 000),即每个数组中的元素数。

第二行包含第一个数组的 N 个元素。

第三行包含第二个数组的 N 个元素。

两个数组中的每个元素都可以是:

● 小于 1 000 的正整数或

● 表示变量的英文字母的小写字母序列(不超过10 个字符)。

输出格式

If it's possible to replace all variables with integer values in a way that the two arrays become equal, print “DA” (Croatian for yes, without the quotation marks). Otherwise print “NE” (Croatian for no).

如果可以用整数值替换所有变量以使两个数组相等,请打印“DA”(克罗地亚语表示是,不带引号)。 否则打印“NE”(克罗地亚语表示否)。

样例 #1

样例输入 #1

3
3 1 2 
3 1 x

样例输出 #1

DA

样例 #2

样例输入 #2

4
4 5 iks ipsilon 
1 iks 3 iks

样例输出 #2

NE

样例 #3

样例输入 #3

5
x 3 x y 3 
x y 2 z 3

样例输出 #3

DA

SCORING

在占总点数 20% 的测试用例中,每个变量将在两个数组的组合中仅出现一次。

在额外占总分 20% 的测试用例中,将只有两个变量,“x”和“y”。 变量可能在两个数组中出现多次。

Clarification of the third sample test:

By introducing substitutions x = 2, y = 3, z = 3, both arrays will become equal (2 3 2 3 3).