#P7304. [COCI 2018/2019 #1] Zamjena
[COCI 2018/2019 #1] Zamjena
Description
Vlatko likes working with arrays of integers.
He wrote down two arrays on paper, each containing elements. Each element is either an integer, or a string representing a variable (the string contains only lowercase letters).
A variable can be replaced by any integer, and the same variable may appear multiple times in the two arrays. If this happens, then during replacement, all positions where the variable appears must be replaced by the same integer.
Vlatko wonders whether it is possible to replace all variables with specific integers so that the two arrays become equal. Two arrays are equal if the integers at all corresponding positions are equal.
Input Format
The first line contains a positive integer , the number of elements in each array.
The second line contains the elements of the first array.
The third line contains the elements of the second array.
Each element in the arrays is one of the following:
- A positive integer less than .
- A string of length at most containing only lowercase letters, representing a variable.
Output Format
If there exists a way to make the two arrays equal after replacement, output DA; otherwise, output NE.
3
3 1 2
3 1 x
DA
4
4 5 iks ipsilon
1 iks 3 iks
NE
5
x 3 x y 3
x y 2 z 3
DA
Hint
Explanation for Sample 3
When replacing with respectively, the two arrays become equal, both being .
Constraints
For of the testdata, each variable appears only once in the two arrays.
For another of the testdata, the arrays contain only two variables .
For of the testdata, .
Note
The score of this problem follows the original COCI setting, with a full score of .
Translated from COCI2018-2019 CONTEST #1 T2 Zamjena.
Translated by ChatGPT 5
京公网安备 11011102002149号