Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Where Are You?
Description There are some theories that if one keeps doing something, the result which that something may lead to will eventually take place. For example, if one crosses a road every day, he will certainly be run over by a car. Jon is a man who believe in such theories. Unfortunately, he lost Cely. But he knows that if he keeps waiting in some place on the earth, they will meet again at last. There are a number of places on the earth. Some are connected by bidirectional roads. (To make things easier, we assume that each road takes exactly 5 days to travel.) Jon’s home in the place numbered zero. For the reason of fate, he will never know where Cely lives. But during the first days, he will go to some places in search of Cely. Each time he goes to a place, he takes the shortest possible path. When he reaches the place without finding Cely, he will immediately take the same way back to his home. A long wait will follow his last trip back home. Cely will appear in some places on some days. If Jon reaches those places as his destination on the very day when Cely appears there, they are lucky to meet. Otherwise they will regrettably miss each other, even if they are in the same place on the way. Jon will do nothing but search blindly and wait reverently. When will they meet? Input The input contains four parts separated by a blank line:
Output Output the earliest day when Jon and Cely will meet. If they will never meet or Jon cannot reach any of his destinations before meeting Cely, output “Being expected..”. Sample Input 4 2 0 1 1 2 2 1 2 3 2 5 1 150 0 3652 Sample Output 3652 Hint Jon’s whole trip of search described in the sample input will be: home (day 0) → place 1 (day 5) → home (day 10) → place 2 (day 20) → home (day 30). On none of these five days can Jon meet Cely. But Jon’s patient wait is rewarded on day 3,652, when Cely arrives at his home. Source POJ Monthly--2006.05.28, Judas |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator