Problem A
Erdős Numbers
Paul Erdős (1913-1996) was a very prolific Hungarian
mathematician. He is famous for the amount of mathematics he
produced (about
Erdős worked a lot on graph theory, which is concerned
with the structure of connections between pairs of objects.
Fittingly, we can treat the collaboration of mathematicians as
a graph problem, where each person is represented by a graph
node, and each coauthored paper forms edges between all pairs
of nodes for the corresponding coauthors on the paper.
Erdős is directly connected with a lot of coauthors with
whom he published papers, who are further connected to other
coauthors by other publications, and so on. This has led to the
concept of an Erdős number. Erdős
himself has an Erdős number of
Write a program to help people who have published papers find their Erdős number – that is, the smallest number of coauthors linking them to Erdős.
Input
Input consists of one database of paper coauthorship,
containing up to
Note: In the sample input, a limited set of Erdős coauthors are listed for space reasons.
Output
For each author (the first name of each line in the input), print the author’s name and his or her Erdős number. Print the authors in the same order they appear in the database. If some author has no connection to Erdős, print no-connection.
Sample Input 1 | Sample Output 1 |
---|---|
PAUL_ERDOS HARVEY_ABBOTT JANOS_ACZEL TAKASHI_AGOH RON_AHARONI MARTIN_AIGNER MIKLOS_AJTAI HARVEY_ABBOTT CHARLES_AULL EZRA_BROWN PAUL_DIERKER PAUL_DIERKER MATTS_ESSEN FRANK_BROWN CHARLES_ROGERS |
PAUL_ERDOS 0 HARVEY_ABBOTT 1 PAUL_DIERKER 2 FRANK_BROWN no-connection |