Under construction

Still being built. Things may change

DevNight Operations

Time limit2sMemory limit1024 MB

Summary
For each conference room, find the shortest distance to its second-preferred communication room, where preference is by distance and then by smaller vertex number.
Level

Medium6 of 10

Topics
Shortest path, Graph, Heap
Solved
No attempts yet

Problem

GIST has held the GIST DevNight (Developers' Night) event every autumn since 2022. At DevNight, developers share information and build friendships. The event is split into a conference held in conference rooms and social activities held in communication rooms.

The 2024 GIST DevNight takes place in a building with NN vertices and MM bidirectional edges, each with a length. Each vertex holds either a conference room or a communication room. There are KK communication rooms: vertices 1 through KK are communication rooms, and vertices K+1K+1 through NN are conference rooms.

When a conference ends, developers move to a communication room. Each person's preference for the communication rooms depends on where they are. Everyone prefers the communication room with the shorter shortest path from their conference room. If two or more communication rooms tie, they prefer the one with the smaller vertex number.

In 2023, developers all used their most preferred communication room. Too many people crowded into a single room, so in 2024 the policy changed: everyone uses their second-most preferred communication room. As the DevNight operator, you want to know how far developers must walk to reach a communication room after a conference in each conference room. Write a program to help Bosung.

Input

The first line contains integers NN, MM, and KK, separated by spaces. (3≤N≤100 0003 \leq N \leq 100\,000, 2≤M≤300 0002 \leq M \leq 300\,000, 2≤K<N2 \leq K < N)

The next MM lines each contain three integers ss, ee, and dd. (1≤s,e≤N1 \leq s, e \leq N, s≠es \neq e, 1≤d≤1061 \leq d \leq 10^6) This means there is an edge of length dd connecting vertices ss and ee.

There is at most one edge between any two vertices. The given graph is always connected.

Output

For every integer xx from K+1K+1 to NN, in order, print the length of the shortest path from vertex xx to its second-most preferred communication room, separated by spaces. The answer can exceed the 32-bit integer range, so be careful.

Examples1

  1. Example 1

    Input
    10 15 3
    1 4 10
    1 5 9
    1 9 3
    2 4 1
    2 6 6
    2 7 5
    3 6 2
    3 8 11
    3 9 11
    4 8 4
    5 6 8
    5 10 7
    7 9 11
    7 10 11
    8 10 11
    
    Expected output
    9 10 6 13 11 11 16