CF24A.Ring road

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all n roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other?

如今,全球各地纷纷引入单向交通,以提高行车安全并缓解交通拥堵。伯兰德政府决定紧跟这一新趋势。过去,伯兰德的 nn 座城市通过 nn 条双向道路构成一个环状结构,即每座城市恰好与另外两座城市直接相连,且从任意一座城市出发均可到达其余任意一座城市。伯兰德政府已将全部 nn 条道路改为单向通行,但很快发现:某些城市之间已无法相互抵达。目前已知每条道路当前的通行方向及其调整方向所需的成本。问:政府最少需要花费多少钱来调整道路方向,才能使得任意两座城市之间均可相互抵达?

输入格式

The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers a__i, b__i, c__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i, 1 ≤ c__i ≤ 100) — road is directed from city a__i to city b__i, redirecting the traffic costs c__i.

第一行包含一个整数 nn(3≤n≤1003 \leq n \leq 100)—— 表示 Berland 国家中城市的数量(同时也是道路的数量)。接下来的 nn 行描述了各条道路。每条道路由三个整数 aia_i、bib_i、cic_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,ai≠bia_i \neq b_i,1≤ci≤1001 \leq c_i \leq 100)描述:该道路为有向道路,从城市 aia_i 指向城市 bib_i,重定向交通的花费为 cic_i。

输出格式

Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.

输出一个整数——政府在道路重定向上需要花费的最少金额,使得从任意城市都可以到达其他任意城市。

输入输出样例

  • 输入#1

    3
    1 3 1
    1 2 1
    3 2 1

    输出#1

    1
  • 输入#2

    3
    1 3 1
    1 2 5
    3 2 1

    输出#2

    2
  • 输入#3

    6
    1 5 4
    5 3 8
    2 4 15
    1 6 16
    2 3 23
    4 6 42

    输出#3

    39
  • 输入#4

    4
    1 2 9
    2 3 8
    3 4 7
    4 1 5

    输出#4

    0

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

首页