24 hour archive: Problem
2943  Find Phones 2943  Find Phones 2943  Find Phones
Statistics  Sub: 330  AC: 144  AC%: 43,64  Score: 1,18 
Created by  Yonny Mondelo Hernández 
Added by  ymondelo20 (20140609) 
Limits 
Total Time: 120000 MS

Test Time:
3000 MS
Memory: 62 MB  Output: 64 MB  Size:
14 KB

Enabled languages  
Available in 
Description
Several students are living inside the campus of the University of Informatics Sciences. The student´s residence is composed by a lot of buildings, each of them with some amount of rooms. Rooms are shared by students year after year, so they become more than simple classmates. They become friends, and almost family for the entire life in some cases.
Each room has their own phone; in a way that you can call each apartment inside the university just dialing for numbers only. There is a system with information about the student´s residence; with the phone numbers of some students (of their apartments), and one arbitrary amount of pair of students which are living in the same apartment right now. The problem is that the given information is not complete, but you can safely assume that it is completely enough for finding the phone numbers of each student in an unequivocal way. This is each student has exactly one phone number and it is possible to find it.
Each room has their own phone; in a way that you can call each apartment inside the university just dialing for numbers only. There is a system with information about the student´s residence; with the phone numbers of some students (of their apartments), and one arbitrary amount of pair of students which are living in the same apartment right now. The problem is that the given information is not complete, but you can safely assume that it is completely enough for finding the phone numbers of each student in an unequivocal way. This is each student has exactly one phone number and it is possible to find it.
Several students are living inside the campus of the University of Informatics Sciences. The student´s residence is composed by a lot of buildings, each of them with some amount of rooms. Rooms are shared by students year after year, so they become more than simple classmates. They become friends, and almost family for the entire life in some cases.
Each room has their own phone; in a way that you can call each apartment inside the university just dialing for numbers only. There is a system with information about the student´s residence; with the phone numbers of some students (of their apartments), and one arbitrary amount of pair of students which are living in the same apartment right now. The problem is that the given information is not complete, but you can safely assume that it is completely enough for finding the phone numbers of each student in an unequivocal way. This is each student has exactly one phone number and it is possible to find it.
Each room has their own phone; in a way that you can call each apartment inside the university just dialing for numbers only. There is a system with information about the student´s residence; with the phone numbers of some students (of their apartments), and one arbitrary amount of pair of students which are living in the same apartment right now. The problem is that the given information is not complete, but you can safely assume that it is completely enough for finding the phone numbers of each student in an unequivocal way. This is each student has exactly one phone number and it is possible to find it.
Several students are living inside the campus of the University of Informatics Sciences. The student´s residence is composed by a lot of buildings, each of them with some amount of rooms. Rooms are shared by students year after year, so they become more than simple classmates. They become friends, and almost family for the entire life in some cases.
Each room has their own phone; in a way that you can call each apartment inside the university just dialing for numbers only. There is a system with information about the student´s residence; with the phone numbers of some students (of their apartments), and one arbitrary amount of pair of students which are living in the same apartment right now. The problem is that the given information is not complete, but you can safely assume that it is completely enough for finding the phone numbers of each student in an unequivocal way. This is each student has exactly one phone number and it is possible to find it.
Each room has their own phone; in a way that you can call each apartment inside the university just dialing for numbers only. There is a system with information about the student´s residence; with the phone numbers of some students (of their apartments), and one arbitrary amount of pair of students which are living in the same apartment right now. The problem is that the given information is not complete, but you can safely assume that it is completely enough for finding the phone numbers of each student in an unequivocal way. This is each student has exactly one phone number and it is possible to find it.
Input specification
The first line contain a integer number 1 <= N <= 500 representing the amount of students. Students are conveniently numbered between 1 and N. The following N lines contains a four digit number (not starting with zero); the phone number of the ith student. If the information is not in the system single zero will be given instead of the phone number. Then an arbitrary amount of pair of students which are living in the same apartment will be given, one pair per line. A single pair will be given as two distinct numbers A and B, both between 1 and N: this mean that students A and B are sharing one apartment and obviously they have the same phone number. You can safely assume that no pair will be given twice in the input.
The first line contain a integer number 1 <= N <= 500 representing the amount of students. Students are conveniently numbered between 1 and N. The following N lines contains a four digit number (not starting with zero); the phone number of the ith student. If the information is not in the system single zero will be given instead of the phone number. Then an arbitrary amount of pair of students which are living in the same apartment will be given, one pair per line. A single pair will be given as two distinct numbers A and B, both between 1 and N: this mean that students A and B are sharing one apartment and obviously they have the same phone number. You can safely assume that no pair will be given twice in the input.
The first line contain a integer number 1 <= N <= 500 representing the amount of students. Students are conveniently numbered between 1 and N. The following N lines contains a four digit number (not starting with zero); the phone number of the ith student. If the information is not in the system single zero will be given instead of the phone number. Then an arbitrary amount of pair of students which are living in the same apartment will be given, one pair per line. A single pair will be given as two distinct numbers A and B, both between 1 and N: this mean that students A and B are sharing one apartment and obviously they have the same phone number. You can safely assume that no pair will be given twice in the input.
Output specification
You must print N lines, each of them with a four digit number; the phone number of the ith student.
You must print N lines, each of them with a four digit number; the phone number of the ith student.
The first line contain a integer number 1 <= N <= 500 representing the amount of students. Students are conveniently numbered between 1 and N. The following N lines contains a four digit number (not starting with zero); the phone number of the ith student. If the information is not in the system single zero will be given instead of the phone number. Then an arbitrary amount of pair of students which are living in the same apartment will be given, one pair per line. A single pair will be given as two distinct numbers A and B, both between 1 and N: this mean that students A and B are sharing one apartment and obviously they have the same phone number. You can safely assume that no pair will be given twice in the input.
Sample input
5
2237
0
8908
8908
0
3 2
1 5
2 4
4 3
Sample output
2237
8908
8908
8908
2237