eolymp
bolt
Try our new interface for solving problems
Problems

Outsourcing

Outsourcing

Mr. Cooper is a manufacturer of science fi ction action gures and he thinks that his local factory causes too many costs. He once heard of certain foreign countries where workers are much less expensive and also more dedicated. So he decided to look for an available action gure factory in some low-wage country to follow the current trend of Outsourcing. It is of course indispensable for him to know if the new factory is capable of producing exactly the same sorts of action gures as the current one. The manufacturing process is organised in terms of assembly stations and transfer stations. An assembly station receives parts from a transfer station, performs a speci c operation on the parts and delivers it to a transfer station. The factories have one starting transfer station delivering raw parts and one nal transfer station receiving the completed action fi gures. One sort of action gures needs a precise sequence \textbf{s_1}, \textbf{s_2}, \textbf{s_3}, ..., \textbf{s_l} of assembly operations. A factory can produce these action gures if there are transfer stations \textbf{t_0}, \textbf{t_1}, ..., \textbf{t_l} such that \textbf{t_0} is the starting station, \textbf{t_l} is the nal station, and for all \textbf{1} ≤ \textbf{i} ≤ \textbf{l} there is an assembly station that receives from \textbf{t_\{i-1\}}, delivers to \textbf{t_i}, and performs operation \textbf{s_i}. Hence, Mr. Cooper wants to know if the local factory and the foreign factory can produce exactly the same sorts of action gures. He recognizes that answering this question may be an involved challenge. So, he decides to spend an amount of his yet to save money on you, to make you develop a computer solution for his problem. \InputFile Input starts with a line containing one integer \textbf{t}, the number of test cases (\textbf{0} < \textbf{t} ≤ \textbf{100}). Each test case starts with a line of six integers \textbf{M_1}, \textbf{N_1}, \textbf{K_1}, \textbf{M_2}, \textbf{N_2} and \textbf{K_2}, where the local factory has \textbf{M_1} assembly stations, \textbf{N_1} transfer stations and \textbf{K_1} different assembly operations (\textbf{1} ≤ \textbf{M_1} ≤ \textbf{10^5}, \textbf{1} ≤ \textbf{N_1} ≤ \textbf{250}, \textbf{1} ≤ \textbf{K_1} ≤ \textbf{250}). The transfer stations are numbered from \textbf{0} to \textbf{N_1-1} the nal station. Then input is followed by \textbf{M_1} lines specifying the assembly stations of the local factory. Every line contains three integers, \textbf{T_in}, \textbf{T_out}, \textbf{S}, where \textbf{T_in} is the transfer station delivering to the assembly station, \textbf{T_out} is the transfer station receiving the assembly results and \textbf{S} gives the performed operation by a number between \textbf{0} and\textbf{K_1-1}. For every transfer station it is guaranteed that there are not two receiving assembly stations performing the same operation. The foreign factory is described analogously by \textbf{M_2}, \textbf{N_2} and \textbf{K_2} and consequently the next \textbf{M_2} lines of input describe the assembly stations of the foreign factory. \OutputFile For every test case print a line containing "\textbf{eligible}" if the local and the foreign factory are capable of manufacturing exactly the same action gures and otherwise print "\textbf{not eligible}".
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
3 4 2 3 4 3
0 2 1
1 3 0
2 3 0
0 2 1
2 1 2
2 3 0
3 3 2 2 2 2
0 1 0
1 1 0
1 2 1
0 0 0
0 1 1
Output example #1
eligible
not eligible
Source ACM ICPC German Collegiate Programming Contest 2012