Byteland Worldbeat Publishers
Time limit5sMemory limit128 MB
Given a sparse matrix of pair efficiencies (some described by row-wise column ranges), decide whether all maximum-size matchings have the same total weight.
Problem
Byteasar is a manager at Byteland Worldbeat Publishers (BWP), which employs composers and lyricists. The artists work in pairs, each pair made of exactly one composer and one lyricist.
Byteasar knows every employee's skills, so he can estimate how productive any composer-lyricist pair would be. The efficiency of a pair is the number of songs it writes per week.
Byteasar wants to form disjoint pairs (every artist belongs to at most one pair) so that the total number of songs per week is as large as possible. Artists left without a partner do not work.
After studying the data, Byteasar suspects that the weekly total does not depend on how the pairs are chosen. Help him check this suspicion: decide whether every way of forming disjoint pairs yields the same total efficiency.
Input
The first line contains one integer (), the number of test cases. The test cases follow.
Each test case begins with a line of three integers , , and (, ): the number of composers, the number of lyricists, and the number of description lines. Composers are numbered to and lyricists to .
Each of the next lines contains four integers , , , and (, , ): composer together with any lyricist from to (inclusive) produces songs per week.
Each composer-lyricist pair is described at most once. A pair that is not listed has efficiency songs per week, yet it may still be formed.
Output
For each test case print one line: TAK (Polish for "yes") if every arrangement of disjoint pairs gives the same total efficiency, or NIE (Polish for "no") otherwise.