#Lutece0195. Controlling Companies
Controlling Companies
Migrated from Lutece 195 Controlling Companies
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns of Mazda. It is said that a company controls company if at least one of the following conditions is satisfied:
- Company = Company
- Company owns more than of Company
- Company controls () companies denoted with each company owning of company and .
Given a list of triples which denote company owning of company , calculate all the pairs in which company controls company . There are at most companies.
Write a program to read the list of triples where , and are positive integers all in the range and find all the pairs so that company controls company .
Input
Line : , the number of input triples to follow
Line : Three integers per line as a triple described above.
Output
List or more companies that control other companies. Each line contains two integers that denote that the company whose number is the first integer controls the company whose number is the second integer. Order the lines in ascending order of the first integer (and ascending order of the second integer to break ties). Do not print that a company controls itself.
Samples
3
1 2 80
2 3 80
3 1 20
1 2
1 3
2 3
Resources
USACO TRAINING selected by rectaflex