CF700C.Break Up

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

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

同样,贝尔兰正经历艰难时期!许多城镇之间的紧张局势甚至可能导致内战。

在雷贝尔兰共有 nn 个城镇,其中某些城镇对之间由双向道路连接。这些道路并不保证使得任一城镇均可通过道路到达其余任意城镇(即图不一定连通)。

城镇 ss 和 tt 宣布彻底断绝一切关系,并打算彻底消除经由道路从 ss 到 tt 的通行可能。目前可能需要关闭若干条道路,使得 ss 到 tt 之间不再存在任何道路路径。每个城镇最多只愿出资关闭一条道路,因此总共关闭的道路数至多为两条。

请帮他们找出一个至多包含两条道路的集合,使得关闭这些道路后,ss 与 tt 之间将不存在任何道路路径。每条道路的关闭预算已预先估算。在所有满足条件的道路集合中,请找出总关闭预算最小的那个集合。

输入格式

The first line of the input contains two integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 30 000) — the number of towns in Berland and the number of roads.

The second line contains integers s and 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, y__i and w__i (1 ≤ x__i, y__i ≤ n, 1 ≤ w__i ≤ 109) — indices of towns connected by the 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.

输入的第一行包含两个整数 nn 和 mm(2 ≤ n ≤ 10002 \leq n \leq 1000,0 ≤ m ≤ 30 0000 \leq m \leq 30\,000)—— 分别表示 Berland 国家中城镇的数量和道路的数量。

第二行包含两个整数 ss 和 tt(1 ≤ s, t ≤ n1 \leq s,\,t \leq n,且 s ≠ ts \neq t)—— 表示关系破裂的两个城镇的编号。

接下来是 mm 行,每行包含三个整数 xix_i、yiy_i 和 wiw_i(1 ≤ xi, yi ≤ n1 \leq x_i,\,y_i \leq n,1 ≤ wi ≤ 1091 \leq w_i \leq 10^9)—— 分别表示第 ii 条道路所连接的两个城镇编号,以及关闭该道路所需的预算。

所有道路均为双向道路。允许同一对城镇之间存在多条道路;也允许存在连接某城镇与其自身的道路(即自环)。

输出格式

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

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

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

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

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

第一行输出断开城镇 ss 与 tt 之间联系所需的最小预算,前提是最多关闭两条道路。

第二行输出数值 cc(0 ≤ c ≤ 20 \le c \le 2)—— 所找到解中需关闭的道路条数。

第三行以任意顺序输出 cc 个互不相同的整数,取值范围为 11 至 mm,表示所关闭道路的编号。注意:道路按输入顺序编号为 11 至 mm。

若无法通过移除至多两条道路使城镇 ss 与 tt 断开连接,则仅输出一行 −1-1。

若存在多种可能的答案,可输出其中任意一种。

输入输出样例

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

输入解题思路,AI测评打分。不知道怎么写?

首页