Question: Please use python Time limit: 3 . 0 0 0 seconds In a certain town there are n intersections connected by two - and one
Please use python
Time limit: seconds
In a certain town there are intersections connected by two and oneway 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, ie it is possible to travel from an intersection to an intersection as well as from to a without violating traffic rules. Because oneway streets are safer, it has been decided to create as much oneway traffic as possible. In order not to make too much confusion it has also been decided that the direction of traffic in already existing oneway 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 twoway 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 twoway street determines one direction of traffic or decides that the street must remain twoway,
writes the answer to the standard output.
Input
The first line of the input contains two integers and where and Integer is the number of intersections in the town and integer is the number of streets.
Each of the next lines contains three integers and where and belongs to If then intersections a and are connected by an oneway street from to If then intersections a and are connected by a twoway street. There is at most one street connecting any two intersections.
Output
The output contains exactly the same number of lines as the number of twoway streets in the input. For each such street in any order the program should write three integers and meaning, the new direction of the street from to or that the street connecting a and remains twoway If there are more than one solution with maximal number of oneway streets then your program should output any of them but just one.
Sample Input
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
