#P7100. [W1] 团

[W1] 团

Description

I have an undirected weighted graph with nn nodes. It has many edges, and it is represented in the following way:

  • There are kk sets. The ii-th set can be written as $S_i=\{(T_1,W_1),(T_2,W_2),\dots,(T_{|S_i|},W_{|S_i|})\}$.
  • For any two pairs (Ti,Wi),(Tj,Wj)(T_i,W_i),(T_j,W_j) in the same set, the graph will contain an edge connecting TiT_i and TjT_j, with edge weight Wi+WjW_i+W_j.

For every node ii, find the shortest path from 11 to ii, i.e., a simple path from 11 to ii with the minimum total edge-weight sum.

Input Format

The first line contains two positive integers n,kn,k.
Next, describe the kk sets.
The first line of the description of set ii contains a positive integer Si|S_i|, which is the size of SiS_i.
Then follow Si|S_i| lines, each containing two positive integers t,wt,w, meaning (t,w)Si(t,w)\in S_i.

Output Format

Output one line with nn positive integers. The ii-th positive integer is the length of the shortest path from 11 to ii. If no path exists, output 0x3f3f3f3f3f3f3f3f=4557430888798830399\textsf{0x3f3f3f3f3f3f3f3f}=4557430888798830399.

5 2
3
1 1
2 1
5 3
3
2 1
3 2
4 1
0 2 5 4 4

Hint

For the first 10%10\% of the testdata, Si=2|S_i|=2.
For the first 20%20\% of the testdata, Si10|S_i|\le10.
For the first 50%50\% of the testdata, N1000,Si2000|N|\le1000,\sum|S_i|\le2000.
For 100%100\% of the testdata, $1\le|N|\le2\cdot10^5,\sum|S_i|\le4\cdot10^5,0\le W_i\le10^9$.

Translated by ChatGPT 5