Nevenka
Greg and Stef both fell in love with their classmate Miranda. They feel irresistible urge to be in her vicinity all the time including the Sunday morning when she goes to a church. A town where they live can be represented by an undirected connected graph. Miranda's house, churches where she prefers to go on Sunday mornings and pubs where Greg and Stef like to drink their
beer are represented by vertices of the graph. Distance between two vertices are defined as the number of edges in the shortest path (i.e. the shortest sequence of vertices where adjacent vertices are connected by an edge) connecting them. Greg and Stef know where Miranda lives and what are her preferred churches. One Sunday they went to two different pubs.
Miranda is acquainted with waitresses of all pubs in town and she asked them to tell her in which pubs Greg and Stef are drinking beer. Since she dislikes them, she waited until she got the information about their whereabouts and then went to a church so that the distance between her and them would be maximal possible all the time. (Greg and Stef will try to come as close as possible to her in a "hunting" manner that will be explained later.) Greg's and Stef's good friend Mike is Miranda's neighbour. He overheard when she told her parents which church she is going to that Sunday and he immediately told that by mobile phone to his friends. Greg and Stef leave pubs at the same moment Miranda leaves her home. They all move with the speed of one edge per minute, although it may happen that Greg or Stef do not move sometimes (i.e. they are waiting at some vertices). Miranda goes along her chosen path to the chosen church (which is known to both friends) no matter what Greg and Stef are doing. They both are trying to get to her as close as possible. Greg and Stef stop with their hunt when Miranda enters the church.
A pair of different pubs is said to grant minimal distance X if for any church Miranda chooses and for any path she goes to it, the minimal distance to her that Greg or Stef, starting their hunt from those pubs, can achieve is X. Write a program that will help Greg and Stef to determine a pair of different pubs that will grant them the minimal possible distance X.
14
4
3 8 9 11
3 1 7 14
13
1 2
2 3
3 4
4 5
5 6
5 7
6 8
3 9
3 10
10 11
10 12
12 13
13 14 Output
1 7Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.