Road Roles
View as PDFAndy has finished wiring a connected undirected network of cities with
weighted roads. He now wants to know how each road relates to the Minimum
Spanning Trees of the network.
For each road, classify it as one of:
forced— the road appears in every MST;optional— the road appears in some MST, but not all;useless— the road appears in no MST.
Input
The first line contains integers and
.
The following lines each contain three integers
,
, and
, describing
an undirected road between cities
and
with weight
.
Cities are numbered from to
. The graph is connected. Multiple roads
between the same pair of cities, and self-loops, are allowed.
Output
Output lines. The
-th line should contain
forced, optional, or
useless, the classification of the -th road in the input.
Constraints
Example 1
Input
3 3
1 2 1
2 3 2
1 3 3
Output
forced
forced
useless
Explanation
The unique MST uses the two lighter roads. The heaviest road can never appear.
Example 2
Input
4 5
1 2 1
2 3 1
1 3 1
1 4 2
2 4 2
Output
optional
optional
optional
optional
optional
Explanation
Any two of the weight- roads connect cities
, and either weight-
road can finish the tree. No road is required in every MST, and none is useless.
Comments