#K71497. Unique Path Weights Assignment
Unique Path Weights Assignment
Unique Path Weights Assignment
You are given a graph described by N nodes and M edges. The graph is supposed to represent a tree when N ≥ 2. Your task is to assign a positive integer weight to each edge such that the sum of the weights along the unique path between any two nodes is distinct. In this problem, you can follow a simple approach: if N is at least 2, assign the weights 1, 2, …, N-1 to the edges, disregarding the actual edge list. If N is less than 2, output -1.
Note: Although the input provides an edge list, the solution ignores it and only uses the number of nodes N. Output -1 if N < 2.
inputFormat
The first line contains an integer N (the number of nodes).
The second line contains an integer M (the number of edges).
Each of the next M lines contains two space-separated integers U and V representing an edge between node U and node V.
outputFormat
If N < 2, output -1.
Otherwise, output N-1 space-separated positive integers representing the weights assigned to each edge.
## sample2
1
1 2
1