Java实现One-way traffic(单向交通)

One-way traffic

In a certain town there are n intersections connected by two- and one-way streets. The town is very
modern so a lot of streets run through tunnels or viaducts. Of course it is possible to travel between
any two intersections in both ways, i.e. it is possible to travel from an intersection a to an intersection
b as well as from b to a without violating traffic rules. Because one-way streets are safer, it has been
decided to create as much one-way traffic as possible. In order not to make too much confusion it has
also been decided that the direction of traffic in already existing one-way streets should not be changed.
Your job is to create a new traffic system in the town. You have to determine the direction of
traffic for as many two-way streets as possible and make sure that it is still possible to travel both ways
between any two intersections.
Write a program that:
• reads a description of the street system in the town from the standard input,
• for each two-way street determines one direction of traffic or decides that the street must remain
two-way,
• writes the answer to the standard output.

Input
The first line of the input contains two integers n and m, where 2 ≤ n ≤ 2000 and n−1 ≤ m ≤ n(n−1)/2.
Integer n is the number of intersections in the town and integer m is the number of streets.
Each of the next m lines contains three integers a, b and c, where 1 ≤ a ≤ n, 1 ≤

你可能感兴趣的:(算法练习题,Java,One-way,traffic,图论之桥)