P7056 [NWRRC 2015] Insider's Information
Description
Ian works for a rating agency that publishes ratings of the best universities. Irene is a journalist who plans to write a scandalous article about the upcoming rating.
Using various social engineering techniques (let's not get into more details), Irene received some insider's information from Ian.
Specifically, Irene received several triples $(a_{i}, b_{i}, c_{i}),$ meaning that in the upcoming rating, university $b_{i}$ stands between universities $a_{i}$ and $c_{i}.$ That is, either $a_{i}$ comes before $b_{i}$ which comes before $c_{i},$ or the opposite. All triples told by Ian are consistent -- let's say that actual rating satisfies them all.
To start working on the first draft of the future article, Irene needs to see at least some approximation to the actual rating. She asked you to find a proposal of a rating in which at least half of the triples known by Irene are satisfied.
Input Format
The first line contains integers $n$ and $m$ , the number of rated universities, and the number of triples given to Irene by Ian $(3 \le n \le 100 000$ ; $1 \le m \le 100 000)$ .
Each of the next $m$ lines contains three distinct integers $a_{i}, b_{i}, c_{i}$ -- the universities making a triple $(1 \le a_{i}, b_{i}, c_{i} \le n)$ .
Output Format
Output the proposal of a rating from the first university to the last one. The proposal rating should satisfy at least $m/2$ triples. If there are many such proposals, output any one of them.
Explanation/Hint
Time limit: 2 s, Memory limit: 256 MB.