PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000117. Những tuyến đường tổng thống có thể đi (President's Path)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những tuyến đường tổng thống có thể đi (President's Path)

President's Path

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn cities connected by mm undirected positive-length roads, with at most one direct road per unordered pair. For every s<ts<t, the President can choose any shortest path from ss to tt. Count distinct original roads lying on at least one such shortest path, counting each road once even if multiple shortest paths use it. Use 00 when tt is unreachable.

Input

First line n,mn,m, followed by mm lines u,v,wu,v,w. Cities are indexed from 11.

Output

Print n(n−1)/2n(n-1)/2 integers in lexicographic pair order (1,2),(1,3),…,(n−1,n)(1,2),(1,3),\ldots,(n-1,n), separated by spaces.

Subtasks

  • Subtask 1 (40 points): 2≤n≤72\le n\le 7, 0≤m≤n(n−1)/20\le m\le n(n-1)/2, 1≤w≤201\le w\le 20. All input conditions remain in force.

  • Subtask 2 (60 points): 2≤n≤5002\le n\le 500, 0≤m≤n(n−1)/20\le m\le n(n-1)/2, 1≤w≤1061\le w\le 10^6. All input conditions remain in force.

Examples

Input

3 3
1 2 1
2 3 1
1 3 2

Output

1 3 1

Explanation

There is 1 eligible road for pair (1,2), 3 eligible roads for (1,3), and 1 for (2,3).