CF1486E.Paired Payment
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cities and m bidirectional roads in the country. The roads in the country form an undirected weighted graph. The graph is not guaranteed to be connected. Each road has it's own parameter w . You can travel through the roads, but the government made a new law: you can only go through two roads at a time (go from city a to city b and then from city b to city c ) and you will have to pay (wab+wbc)2 money to go through those roads. Find out whether it is possible to travel from city 1 to every other city t and what's the minimum amount of money you need to get from 1 to t .
输入格式
First line contains two integers n , m ( 2≤n≤105 , 1≤m≤min(2n⋅(n−1),2⋅105) ).
Next m lines each contain three integers vi , ui , wi ( 1≤vi,ui≤n , 1≤wi≤50 , ui=vi ). It's guaranteed that there are no multiple edges, i.e. for any edge (ui,vi) there are no other edges (ui,vi) or (vi,ui) .
输出格式
For every city t print one integer. If there is no correct path between 1 and t output −1 . Otherwise print out the minimum amount of money needed to travel from 1 to t .
输入输出样例
输入#1
5 6 1 2 3 2 3 4 3 4 5 4 5 6 1 5 1 2 4 2
输出#1
0 98 49 25 114
输入#2
3 2 1 2 1 2 3 2
输出#2
0 -1 9
说明/提示
The graph in the first example looks like this.
In the second example the path from 1 to 3 goes through 2 , so the resulting payment is (1+2)2=9 .