#P1475. [USACO2.3] 控制公司 Controlling Companies
[USACO2.3] 控制公司 Controlling Companies
Description
Some companies are partial owners of other companies because they own a portion of the shares issued by those companies.
It is said that if at least one of the following three conditions is met, company can control company :
- Company = company .
- Company owns more than of company 's stock.
- Company controls () companies, denoted , each company owns of company 's stock, and .
You are given a table where each row contains three numbers : it means company owns of company . Compute all pairs indicating that company controls company . There are at most companies.
Input Format
The first line contains an integer , the number of rows in the table.
Each of the next lines contains three integers , meaning company owns of company 's stock.
Output Format
Output zero or more companies that control other companies. Each line contains two integers , meaning company controls company . Sort the output pairs in ascending order by as the primary key and as the secondary key.
Do not output cases where a company controls itself (i.e., all pairs must satisfy ).
3
1 2 80
2 3 80
3 1 20
1 2
1 3
2 3
Hint
Translated from NOCOW.
USACO 2.3.
Translated by ChatGPT 5
京公网安备 11011102002149号