#t520. 分糖果
分糖果
Sharing Candy
Special for beginners, ^_^
Problem Description
In our childhood we took joy in sharing good things with friends. One day, child C got a lot of candy and is going to share it with his close friends.
It takes 1 second for candy to be passed from one person to another, and the same child will not receive candy twice. Since there is plenty of candy, if a child receives candy at some moment, he will divide it into several portions and give them to the children beside him who have not yet received candy, and he will also eat some himself.
Because they are greedy, the children cannot wait until all the candy is distributed; they eat the candy while handing it out. Each child takes seconds from receiving the candy to finishing it. If child C starts distributing candy in the first second, in which second will all children have finished eating their candy?
Input Format
The first line contains three numbers : the number of children, the number of relationships, and the number of child C.
The second line contains a number , the time a child takes to eat the candy.
The next lines each contain two integers, indicating that two children are beside each other.
Output Format
One number: the time when all children have finished eating their candy.
Sample Input 1
4 3 1
2
1 2
2 3
1 4
Sample Output 1
5
Hint
In the first second, the candy is in the hands of child 1.
In the second second, the candy reaches children 2 and 3.
In the third second, the candy reaches child 4; at this moment child 1 has finished eating.
In the fourth second, children 2 and 3 finish.
In the fifth second, child 4 finishes.
So the answer is 5.
Constraints
1s, 1024KiB for each test case.
of the data satisfies: .
of the data satisfies: .
of the data satisfies: .
The number of relationships satisfies , and no relationship is described more than once.