Pro.ID10143 TitleControlling Companies Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10143 AC36 Submit153 Ratio23.53% 时间&空间限制描述Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns 12% of Mazda. It is said that a company A controls company B if at least one of the following conditions is satisfied:
Given a list of triples (i, j, p) which denote company i owning p% of company j, calculate all the pairs (h, s) in which company h controls company s. There are at most 100 companies. Write a program to read the list of triples (i, j, p) where i, j and p are positive integers all in the range (1..100) and find all the pairs (h, s) so that company h controls company s. 输入Multiple test cases. For each case: Line 1: n, the number of input triples to follow Line 2..n+1: Three integers per line as a triple (i, j, p) described above. 输出Description Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns 12% of Mazda. It is said that a company A controls company B if at least one of the following conditions is satisfied:
Given a list of triples (i, j, p) which denote company i owning p% of company j, calculate all the pairs (h, s) in which company h controls company s. There are at most 100 companies. Write a program to read the list of triples (i, j, p) where i, j and p are positive integers all in the range (1..100) and find all the pairs (h, s) so that company h controls company s. Input Multiple test cases. For each case: Line 1: n, the number of input triples to follow Line 2..n+1: Three integers per line as a triple (i, j, p) described above. Output For each case: List 0 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. Output a blank line after each case. Sample Input 3 Sample Output 1 2 Source 样例输入3 样例输出1 2 作者 |