2014 Canadian Computing Competition, Stage 1

Problem J5/S2: Assigning Partners

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 ≤ 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.

Sample Input 1

4
Ada Alan Grace John
John Grace Alan Ada

Sample Output 1

good

Explanation for Sample 1

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

Sample Input 2

7
Rich Graeme Michelle Sandy Vlado Ron Jacob
Ron Vlado Sandy Michelle Rich Graeme Jacob

Sample Output 2

bad

Explanation for Sample 1

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.

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 27, 2014

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Underneath Sample output 2, it says explanation for sample 1??
Confusing.


Can someone check my code out? Thanks

The names aren't necessarily in order.
EX.
A B C D
B A D C

You are missing an important part of the question. Reread the question.
Your code effectively only takes the last of the names of each row into consideration before you output anything.
Furthermore, you have submitted a total of once at the time of this post. At least try to debug by yourself first before spamming the comments feed. There are many easy test cases you could have made and solved by hand which would have allowed you to immediately realize where your solution is incorrect. One such example is
3 
A X Y
A Y X

Thank you. I like the make my own cases idea

Don't worry, this is an extremely difficult problem. It is completely understandable that you did not get it first try. I think the only questions possibly harder than this one on the CCC Junior were J2, J3, and J4.

thanks -.-

OK so the title at the top says Problem J4/S2 when this is actually J5/S2. I am pretty sure this is a misnaming error, since the name of the problem in the submissions says J5 which is right.