CF700C.Break Up

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Again, there are hard times in Berland! Many towns have such tensions that even civil war is possible.

There are nn 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 ss and tt 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 ss to tt 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 ss and tt 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.

输入格式

The first line of the input contains two integers nn and mm ( 2<=n<=10002<=n<=1000 , 0<=m<=300000<=m<=30000 ) — the number of towns in Berland and the number of roads.

The second line contains integers ss and tt ( 1<=s,t<=n1<=s,t<=n , sts≠t ) — indices of towns which break up the relationships.

Then follow mm lines, each of them contains three integers xix_{i} , yiy_{i} and wiw_{i} ( 1<=xi,yi<=n1<=x_{i},y_{i}<=n , 1<=wi<=1091<=w_{i}<=10^{9} ) — indices of towns connected by the ii -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.

输出格式

In the first line print the minimum budget required to break up the relations between ss and tt , if it is allowed to close no more than two roads.

In the second line print the value cc ( 0<=c<=20<=c<=2 ) — the number of roads to be closed in the found solution.

In the third line print in any order cc diverse integers from 11 to mm — indices of closed roads. Consider that the roads are numbered from 11 to mm in the order they appear in the input.

If it is impossible to make towns ss and tt disconnected by removing no more than 22 roads, the output should contain a single line -1.

If there are several possible answers, you may print any of them.

输入输出样例

  • 输入#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 3
    

    输出#1

    8
    2
    2 7
    
  • 输入#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 7
    

    输出#2

    9
    2
    4 5
    
  • 输入#3

    5 4
    1 5
    2 1 3
    3 2 1
    3 4 4
    4 5 2
    

    输出#3

    1
    1
    2
    
  • 输入#4

    2 3
    1 2
    1 2 734458840
    1 2 817380027
    1 2 304764803
    

    输出#4

    -1
    
首页