Canadian Computing Competition: 2016 Stage 1, Senior #3
Jo is a blogger, specializing in the critique of restaurants. Today, she wants to visit all the Vietnamese Pho restaurants in the Waterloo area, in order to determine which one is the best.
There are
In computer science, a road network with this structure is called a tree. Here are three examples of trees:
One property that is true for all trees is that there is exactly one path that does not repeat any roads between any two points in the tree.
What is the minimal length of time that Jo needs to spend on traveling on roads to visit all of the Pho restaurants?
Input Specification
The first line of input contains 2 integers,
The second line of input contains
The next
- For 3 of the 15 available marks,
and . - For an additional 3 of the 15 available marks,
and . - For an additional 3 of the 15 available marks,
and . - For an additional 4 of the 15 available marks,
.
Output Specification
Your program should output one line, containing one integer - the minimum amount of time Jo needs to spend traveling on roads in order to visit all Pho restaurants, in minutes.
Sample Input 1
8 2
5 2
0 1
0 2
2 3
4 3
6 1
1 5
7 3
Output for Sample Input 1
3
Explanation for Output for Sample Input 1
The path between
Sample Input 2
8 5
0 6 4 3 7
0 1
0 2
2 3
4 3
6 1
1 5
7 3
Output for Sample Input 2
7
Explanation for Output for Sample Input 2
If Jo begins at restaurant 6, she will only need to use 7 roads. One possible path that she can take is:
Comments
If youre having trouble, try this:
The answer should be 4
Who's Jo?
Jo Mama
The tree examples look like they are trying to spell something