Under construction

Still being built. Things may change

Two Shortest Paths

Time limit5sMemory limit1024 MB

Summary
Given a directed weighted graph, find for each vertex i the minimum total cost of two edge-disjoint paths from vertex 1 to i.
Level

Hard8 of 10

Topics
Graph, Shortest path
Solved
No attempts yet

Problem

The graph has NN vertices and MM edges. Each edge is directed and has a non-negative integer weight.

For every 2≤i≤N2 \le i \le N, find the minimum total cost of two non-overlapping paths from vertex 1 to vertex ii. Two paths do not overlap if they share no edge. The cost of a path is the sum of the weights of the edges on it.

Input

The first line contains the number of test cases TCTC. Each of the following TCTC test cases is given on separate lines.

Each test case has the following format.

  • The first line contains two integers NN and MM.
  • Each of the next MM lines contains three integers uiu_i, viv_i, wiw_i. This means there is an edge from vertex uiu_i to vertex viv_i with weight wiw_i.

Output

For each test case, print one line with N−1N-1 integers. The ii-th integer is the minimum total cost of two non-overlapping paths from vertex 1 to vertex i+1i+1. If two non-overlapping paths do not exist, print -1.

Constraints

  • 1≤ui,vi≤N1 \le u_i, v_i \le N
  • ui≠viu_i \neq v_i
  • i≠j  ⟺  (ui,vi)≠(uj,vj)i \neq j \iff (u_i, v_i) \neq (u_j, v_j)
  • 0≤wi≤1090 \le w_i \le 10^9
  • Vertex 1 can reach every vertex.
  • In one input file, the sum of NN is at most 100 000100\,000.
  • In one input file, the sum of MM is at most 1 000 0001\,000\,000.

Examples2

  1. Example 1

    Input
    3
    3 4
    1 2 1
    1 3 2
    2 3 3
    3 2 4
    2 2
    1 2 1
    2 1 0
    5 7
    1 2 4
    2 3 3
    1 3 8
    3 5 3
    4 5 2
    5 4 7
    1 5 1
    
    Expected output
    7 6
    -1
    -1 15 -1 11
    
  2. Example 2

    Input
    2
    4 9
    1 2 18
    2 3 1
    3 4 11
    4 3 2
    4 1 30
    3 1 24
    3 2 22
    1 3 18
    2 4 1
    4 5
    1 2 2
    1 3 14
    1 4 4
    2 1 20
    2 3 30
    
    Expected output
    58 37 48
    -1 46 -1