Description Again, there are hard times in Berland! Many towns have such tensions that even civil war is possible. There are n n n towns in Reberland, some pairs of which connected by two-way roads. It is not guaranteed that it is possible to reach one town from any other town using these roads. Towns s s s and t t t announce the final break of any relationship and intend to rule out the possibility of moving between them by the roads. Now possibly it is needed to close several roads so that moving from s s s to t t t using roads becomes impossible. Each town agrees to spend money on closing no more than one road, therefore, the total number of closed roads will be no more than two. Help them find set of no more than two roads such that there will be no way between s s s and t t t after closing these roads. For each road the budget required for its closure was estimated. Among all sets find such that the total budget for the closure of a set of roads is minimum.
Input The first line of the input contains two integers n n n and m m m ( 2 ≤ n ≤ 1000 2 ≤ n ≤ 1000 2 ≤ n ≤ 1000, 0 ≤ m ≤ 30 000 0 ≤ m ≤ 30 000 0 ≤ m ≤ 30 000) — the number of towns in Berland and the number of roads. The second line contains integers s s s and t t t ( 1 ≤ s , t ≤ n , s ≠ t 1 ≤ s, t ≤ n,s ≠ t 1 ≤ s, t ≤ n,s = t) — indices of towns which break up the relationships. Then follow m lines, each of them contains three integers x i x_i xi, y i y_i yi and w i w_i wi ( 1 ≤ x i , y i ≤ n , 1 ≤ w i ≤ 1 0 9 1 ≤ x_i, y_i ≤ n, 1 ≤ w_i ≤ 10^9 1 ≤ xi, yi ≤ n,1 ≤ wi ≤ 109) — indices of towns connected by the i i i-th road, and the budget on its closure. All roads are bidirectional. It is allowed that the pair of towns is connected by more than one road. Roads that connect the city to itself are allowed.
Output In the first line print the minimum budget required to break up the relations between s s s and t t t, if it is allowed to close no more than two roads. In the second line print the value c c c ( 0 ≤ c ≤ 2 0 ≤ c ≤ 2 0 ≤ c ≤ 2) — the number of roads to be closed in the found solution. In the third line print in any order c c c diverse integers from 1 1 1 to m m m — indices of closed roads. Consider that the roads are numbered from 1 1 1 to m m m in the order they appear in the input. If it is impossible to make towns s s s and t t t disconnected by removing no more than 2 2 2 roads, the output should contain a single line -1. If there are several possible answers, you may print any of them.
Sample Input 1
6 7 1 6 2 1 6 2 3 5 3 4 9 4 6 4 4 6 5 4 5 1 3 1 3Sample Output 1
8 2 2 7Sample Input 2
6 7 1 6 2 3 1 1 2 2 1 3 3 4 5 4 3 6 5 4 6 6 1 5 7Sample Output 2
9 2 4 5Sample Input 3
5 4 1 5 2 1 3 3 2 1 3 4 4 4 5 2Sample Output 3
1 1 2Sample Input 4
2 3 1 2 1 2 734458840 1 2 817380027 1 2 304764803Sample Output 4
-1给出一个无向图,可能有重边和自环,给定 s s s和 t t t,至多删除两条边,让 s s s, t t t不连通,问方案的权值和最小为多少,并且输出删的边。
参考博客:codeforces 700C Break Up 暴力枚举边+边双缩点(有重边) (我觉得他写得太妙了,所以就直接粘贴了)
分类讨论:
s s s, t t t本就不连通,输出0即可; s s s, t t t连通但是只有一条完全不相同的路径; s s s, t t t连通但是只有两条条完全不相同的路径; s s s, t t t连通但是有不少于 3 3 3条完全不相同的路径。对于后三种情况,枚举删掉的其中一条边,然后双缩点,再讨论:
删边后, s s s和 t t t在一个双连通分量,此时符合上述第4个情况,无解;本身就不连通,这时只删除枚举的边就好了;连通的话,找到 s s s连通分量到 t t t连通分量中最小的桥就好了,删除的是枚举的边和最小 的桥边。最终把合法的方案取最小即可。