eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Stock Chase

Stock Chase

I have to admit, the solution \textbf{I} proposed last year for solving the bank cash crisis didn’t solve the whole economic crisis. As it turns out, companies don’t have that much cash in the first place. They have assets which are primarily shares in other companies. It is common, and acceptable, for one company to own shares in another. What complicates the issue is for two companies to own shares in each other at the same time. If you think of it for a moment, this means that each company now (indirectly) controls its own shares. New market regulation is being implemented: No company can control shares in itself, whether directly or indirectly. The Stock Market Authority is looking for a computerized solution that will help it detect any buying activity that will result in a company controlling its own shares. It is obvious why they need a program to do so, just imagine the situation where company \textbf{A} buying shares in \textbf{B}, \textbf{B} buying in \textbf{C}, and then \textbf{C} buying in \textbf{A}. While the first two purchases are acceptable. The third purchase should be rejected since it will lead to the three companies controlling shares in themselves. The program will be given all purchasing transactions in chronological order. The program should reject any transaction that could lead to one company controlling its own shares. All other transactions are accepted. \InputFile Your program will be tested on one or more test cases. Each test case is specified on \textbf{T}+\textbf{1} lines. The first line specifies two positive numbers: (\textbf{0} < \textbf{N} ≤ \textbf{234}) is the number of companies and (\textbf{0} < \textbf{T} ≤ \textbf{100, 000}) is the number of transactions. \textbf{T} lines follow, each describing a buying transaction. Each transaction is specified using two numbers \textbf{A} and \textbf{B} where (\textbf{0} < \textbf{A}, \textbf{B} ≤ \textbf{N}) indicating that company \textbf{A} wants to buy shares in company \textbf{B}. The last line of the input file has two zeros. \OutputFile For each test case, print the following line: \textbf{k.} \textbf{R} Where \textbf{k} is the test case number (starting at one), \textbf{R} is the number of transactions that should be rejected. \textbf{Note}: There is a blank space before \textbf{R}.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
3 6
1 2
1 3
3 1
2 1
1 2
2 3
0 0
Выходные данные #1
1. 2