CF48G.Galaxy Union

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

In a far away galaxy there are nn inhabited planets numbered with numbers from 11 to nn . One day the presidents of all the nn planets independently from each other came up with an idea of creating the Galaxy Union. Now they need to share this wonderful idea with their galaxymates, that’s why each president is busy working out a project of negotiating with the other presidents.

For negotiations between some pairs of the planets there are bidirectional communication channels, each of which is characterized with "dial duration" tit_{i} which, as a rule, takes several hours and exceeds the call duration greatly. Overall the galaxy has nn communication channels and they unite all the planets into a uniform network. That means that it is possible to phone to any planet vv from any planet uu , perhaps, using some transitional planets v1v_{1} , v2v_{2} , ..., vmv_{m} via the existing channels between uu and v1v_{1} , v1v_{1} and v2v_{2} , ..., vm1v_{m-1} and vmv_{m} , vmv_{m} and vv . At that the dial duration from uu to vv will be equal to the sum of dial durations of the used channels.

So, every president has to talk one by one to the presidents of all the rest n1n-1 planets. At that the negotiations take place strictly consecutively, and until the negotiations with a planet stop, the dial to another one does not begin. As the matter is urgent, from the different ways to call the needed planet every time the quickest one is chosen. Little time is needed to assure another president on the importance of the Galaxy Union, that’s why the duration of the negotiations with each planet can be considered equal to the dial duration time for those planets. As the presidents know nothing about each other’s plans, they do not take into consideration the possibility that, for example, the sought president may call himself or already know about the founding of the Galaxy Union from other sources.

The governments of all the nn planets asked you to work out the negotiation plans. First you are to find out for every president how much time his supposed negotiations will take.

输入格式

The first line contains an integer nn ( 3<=n<=2000003<=n<=200000 ) which represents the number of planets in the Galaxy and the number of communication channels equal to it. The next nn lines contain three integers each aia_{i} , bib_{i} and tit_{i} ( 1<=ai,bi<=n,aibi,1<=ti<=1031<=a_{i},b_{i}<=n,a_{i}≠b_{i},1<=t_{i}<=10^{3} ) that represent the numbers of planet joined by a communication channel and its "dial duration". There can be no more than one communication channel between a pair of planets.

输出格式

In the first line output nn integers — the durations of the supposed negotiations for each president. Separate the numbers by spaces.

输入输出样例

  • 输入#1

    3
    1 2 3
    2 3 2
    1 3 1
    

    输出#1

    4 5 3
    
  • 输入#2

    3
    1 2 3
    2 3 2
    1 3 5
    

    输出#2

    8 5 7
    
  • 输入#3

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

    输出#3

    12 8 8 8
    
首页