XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Saratov - L. Increasing Costs

Problem L. Increasing Costs

Input file: standard input
Output file: standard output
Time limit: 4 seconds
Memory limit: 256 mebibytes

Berland consists of n cities labeled from 1 to n. The city number 1 is the capital of Berland. There are m two-way roads between some cities. Roads can intersect only in cities. There is no more than one road between each pair of cities, and there is no road that connects a city to itself. If you are moving by j-th road in any direction, you have to pay the tax equal to cj. It is possible to reach any city from the capital using only the given m roads.
You are the CEO of a delivery company, its main office is located in the capital. Your company delivers different goods to every city of Berland, so for each city, you chose some route from the capital to that city which minimized the total sum of taxes of all roads in the route. Let dk be the total cost of the chosen route from the capital to city k.
The government has decided to choose exactly one road (you don’t know which one) and increase the tax for using it. So, for each road, you want to know how many cities will be affected if the tax for using this road is increased. City k is affected if, after the tax is increased, you can’t choose a route such that the total cost of this route is equal to dk.

Input
The first line contains two integers n and m: the number of cities and the number roads in Berland (2 ≤ n ≤ 2 · 105, n − 1 ≤ m ≤ 2 · 105).
Each of the next m lines contains three space-separated integers: uj, vj, and cj (1 ≤ uj; vj ≤ n,
1 ≤ cj ≤ 109). These mean that the road number j between cities uj and vj initially has tax equal to cj.
There is no more than one road between each pair of cities, and there is no road that connects a city to itself. It is guaranteed that it is possible to reach every city from the capital using the given roads.

Output
Print m integers, one per line. The j-th integer must be the number of cities affected by increasing the cost of j-th road.

Example
standard input
6 6
1 2 2
2 3 1
3 4 7
4 5 4
5 2 4
4 6 4
standard output
5 1 0 0 1 1


无向图上,求如果将其中一条边的权值增加,1号点到其他点的最短路当中,有几个会改变。


先求出1号点到每个点的最短路,之后删去无用的路并将其变为有向图。
这时,求出图的支配树,直接DP即可。

#include <cstdio>
#include <iostream>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值