|
||||||||||
Random MazeTime Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1743 Accepted Submission(s): 726 Problem Description In the game ¡°A Chinese Ghost Story¡±, there are many random mazes which have some characteristic£º 1.There is only one entrance and one exit. 2.All the road in the maze are unidirectional. 3.For the entrance, its out-degree = its in-degree + 1. 4.For the exit, its in-degree = its out-degree + 1. 5.For other node except entrance and exit, its out-degree = its in-degree. There is an directed graph, your task is removing some edge so that it becomes a random maze. For every edge in the graph, there are two values a and b, if you remove the edge, you should cost b, otherwise cost a. Now, give you the information of the graph, your task if tell me the minimum cost should pay to make it becomes a random maze. Input The first line of the input file is a single integer T. The rest of the test file contains T blocks. For each test case, there is a line with four integers, n, m, s and t, means that there are n nodes and m edges, s is the entrance's index, and t is the exit's index. Then m lines follow, each line consists of four integers, u, v, a and b, means that there is an edge from u to v. 2<=n<=100, 1<=m<=2000, 1<=s, t<=n, s != t. 1<=u, v<=n. 1<=a, b<=100000 Output For each case, if it is impossible to work out the random maze, just output the word ¡°impossible¡±, otherwise output the minimum cost.(as shown in the sample output) Sample Input
Sample Output
Source | ||||||||||
|