DevNight Operations
Time limit2sMemory limit1024 MB
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 vertices and bidirectional edges, each with a length. Each vertex holds either a conference room or a communication room. There are communication rooms: vertices 1 through are communication rooms, and vertices through 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 , , and , separated by spaces. (, , )
The next lines each contain three integers , , and . (, , ) This means there is an edge of length connecting vertices and .
There is at most one edge between any two vertices. The given graph is always connected.
Output
For every integer from to , in order, print the length of the shortest path from vertex to its second-most preferred communication room, separated by spaces. The answer can exceed the 32-bit integer range, so be careful.