10235 - 控制公司

有些公司是其他公司的部分拥有者,因为他们获得了其他公司发行的股票的一部分。例如,福特公司拥有马自达公司12%的股票。据说,如果至少满足了以下条件之一,公司A就可以控制公司B了:

公司A = 公司B。 公司A拥有大于50%的公司B的股票。 公司A控制K(K >= 1)个公司,记为C1, ..., CK,每个公司Ci拥有xi%的公司B的股票,并且x1+ .... + xK > 50%。 你将被给予一系列的三对数(i,j,p),表明公司i享有公司j的p%的股票。计算所有的数对(h,s),表明公司h控制公司s。至多有100个公司。

写一个程序读入三对数(i,j,p),i,j和p是都在范围(1..100)的正整数,并且找出所有的数对(h,s),使得公司h控制公司s。

输入

第一行: N,表明接下来三对数的数量。 第二行到第N+1行: 每行三个整数作为一个三对数(i,j,p),如上文所述。

输出

输出零个或更多个的控制其他公司的公司。每行包括两个整数表明序号为第一个整数的公司控制了序号为第二个整数的公司。将输出的每行以第一个数字升序排列(并且第二个数字也升序排列来避免并列)。请不要输出控制自己的公司。

样例

输入

3
1 2 80
2 3 80
3 1 20

输出

1 2
1 3
2 3

提示

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:

Company A = Company B Company A owns more than 50% of Company B Company A controls K (K >= 1) companies denoted C1, ..., CK with each company Ci owning xi% of company B and x1 + .... + xK > 50%. 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.

PROGRAM NAME: concom INPUT FORMAT 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.

SAMPLE INPUT (file concom.in) 3 1 2 80 2 3 80 3 1 20

OUTPUT FORMAT 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. SAMPLE OUTPUT (file concom.out) 1 2 1 3 2 3

时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题