HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > IMPC16 Group Contests > problem:


F1. 50841 - My grand-grand-grandfather

IMPC16 Group Contests

Start: Jan.16.2016 at 10:00:00 AM
Finish: Jan.16.2016 at 02:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (2)

Contest problems

• 22. 50874 - Apartment Building Adm...
• 23. 50875 - Take m-out
• 24. 50876 - He is my cousin
• 25. 50877 - Friendly Queue
• 32. 50926 - School Mail Merge
• 33. 50927 - Health Expenses
• 34. 50928 - War Of Battleships
• 35. 50929 - Present from your uncles
• F1. 50841 - My grand-grand-gr...
• F2. 50936 - Saving the Soldiers
• F4. 50977 - Gaussian Elimination
• F5. 50978 - Albanian Coders
• F6. 50979 - Minimum access cost for...

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Prepared by Ibrahim Mesecan.

My grand-grand-grandfather

In a table you are given the parent (or ancestor) relationship of some people. For example
  3 5
  4 7
where 3 is the child (or grandchild) of 5, and 4 is the child of 7, etc. Note: if one has been given two ancestors, the smaller one is the ancestor of this person. And, the ancestor of the second person do not change. And in the beginning, everone is parent of himself.

Question:Write a program that finds the top most ancestors of k people.

Input specification
You are first given three numbers: the number of people (n: where people have the IDs from 1 to n); the number of parent child relationships (m) and the number of people whose top most ancestors are asked (k) where 1 ≤ (n, m, k) ≤ 10,000.

Output specification:
For all k people, find their top most ancestors and show. If anyone is not provided parent information, show his own id.

Sample Input
7 5 4
3 5
4 7
5 4
6 4
1 2
3
6
2
1
Sample Output
3 4 2 1



Для отправки решений необходимо выполнить вход.

www.contester.ru