CF1725M.Moving Both Hands
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Pak Chanek is playing one of his favourite board games. In the game, there is a directed graph with N vertices and M edges. In the graph, edge i connects two different vertices Ui and Vi with a length of Wi . By using the i -th edge, something can move from Ui to Vi , but not from Vi to Ui .
To play this game, initially Pak Chanek must place both of his hands onto two different vertices. In one move, he can move one of his hands to another vertex using an edge. To move a hand from vertex Ui to vertex Vi , Pak Chanek needs a time of Wi seconds. Note that Pak Chanek can only move one hand at a time. This game ends when both of Pak Chanek's hands are on the same vertex.
Pak Chanek has several questions. For each p satisfying 2≤p≤N , you need to find the minimum time in seconds needed for Pak Chanek to end the game if initially Pak Chanek's left hand and right hand are placed on vertex 1 and vertex p , or report if it is impossible.
输入格式
The first line contains two integers N and M ( 2≤N≤105 , 0≤M≤2⋅105 ) — the number of vertices and edges in the graph.
The i -th of the next M lines contains three integers Ui , Vi , and Wi ( 1≤Ui,Vi≤N , Ui=Vi , 1≤Wi≤109 ) — a directed edge that connects two different vertices Ui and Vi with a length of Wi . There is no pair of different edges i and j such that Ui=Uj and Vi=Vj .
输出格式
Output a line containing N−1 integers. The j -th integer represents the minimum time in seconds needed by Pak Chanek to end the game if initially Pak Chanek's left hand and right hand are placed on vertex 1 and vertex j+1 , or −1 if it is impossible.
输入输出样例
输入#1
5 7 1 2 2 2 4 1 4 1 4 2 5 3 5 4 1 5 2 4 2 1 1
输出#1
1 -1 3 4
说明/提示
If initially Pak Chanek's left hand is on vertex 1 and his right hand is on vertex 5 , Pak Chanek can do the following moves:
- Move his right hand to vertex 4 in 1 second.
- Move his left hand to vertex 2 in 2 seconds.
- Move his left hand to vertex 4 in 1 second.
In total it needs 1+2+1=4 seconds. It can be proven that there is no other way that is faster.