Problem list
Log in
#r03690 · CCC 2014 Senior

Assigning Partners

Bronze I 2.0 s 256 MB

The CEMC is organizing a workshop with an activity involving pairs of students. They decided to assign partners ahead of time. You need to determine if they did this consistently. That is, whenever A is a partner of B, then B is also a partner of A, and no one is a partner of themselves.

Input

The input consists of three lines. The first line consists of an integer $N~(1 < N \leq 30)$, which is the number of students in the class. The second line contains the first names of the $N$ students separated by single spaces. (Names contain only uppercase or lowercase letters, and no two students have the same first name). The third line contains the same $N$ names in some order, separated by single spaces.

The positions of the names in the last two lines indicate the assignment of partners: the $i$th name on the second line is the assigned partner of the $i$th name on the third line.

Output

The output will be good if the two lists of names are arranged consistently, and bad if the arrangement of partners is not consistent.

Example 1

Input
4
Ada Alan Grace John
John Grace Alan Ada
Output
good

Ada and John are partners, and Alan and Grace are partners. This arrangement is consistent.

Example 2

Input
7
Rich Graeme Michelle Sandy Vlado Ron Jacob
Ron Vlado Sandy Michelle Rich Graeme Jacob
Output
bad

Graeme is partnered with Vlado, but Vlado is partnered with Rich. This is not consistent. It is also inconsistent because Jacob is partnered with himself.

Source
CCC 2014 Senior
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code