Grouping Chefs

All submissions for this problem are available.
The Chef's last idea was that some cooks might work better in pairs. But now he thinks that it is better to form one group of Chefs in order to make larger increase of foods quality. All pairs of employees in this group must be compatible. We call such group friendly. Chef provides you the list of compatible pairs of employees. Also for each employee, the Chef has assigned a number estimating how well the overall quality of the food might increase if this employee will be in the group. Strangely enough, the Chef estimates that picking the i'th employee in the group will increase the quality of food prepared in his kitchen by exactly 2^{ci} where c_{i} are nonnegative integer. Also note that Chef has assigned different numbers for his employees. Chef doesn't want to form just one friendly group of employees that make the largest increase of food quality. He wants to have several possibilities of such groups. Namely he wants to know K best friendly groups by the value of increase of food quality. Note that Chef considers only nonempty groups. Help him to find these groups.
Input
The first line contains a single integer T denoting the number of test cases (at most 20). Each test case begins with three integers N, M and K. Here, N is the number of employees (between 1 and 10000), M is the number of compatible pairs of employees (between 0 and 20000) and K is the number of friendly groups that you need to find (between 1 and 50). The employees are numbered from 0 to N1. The next line contains N integers c_{0}, c_{1}, ..., c_{N1} described in the problem statement. These numbers are different nonnegative integers not greater than 10^{9}. The next M lines describe pairs of compatible employees, one per line. The i'th such line contains two distinct integers u_{i}, v_{i} between 0 and N1.
No pair of employees will be given more than once in the input. That is, for distinct indices i and j, we do not have both u_{i} = u_{j} and v_{i} = v_{j}, nor do we have both u_{i} = v_{j} and v_{i} = u_{j}.
Output
The output for each test case consists of K+1 lines. Each of the first K lines consists of the employees indices that are used in i'th maximum total value grouping where i is the number of line. These indices should be given in increasing order with a single space between consecutive numbers. Last line of the output of each test case must be blank. It is guaranteed that there exist at least K different friendly groups. If there is more than one possible output, then any will do.
Example
Input: 2 4 5 11 4 2 3 1 0 1 0 2 1 2 2 3 3 1 1 0 1 1000000000 Output: 0 1 2 0 2 0 1 0 1 2 3 1 2 2 3 2 1 3 1 3 0
Author:  anton_lunyov 
Tester:  friggstad 
Editorial  http://discuss.codechef.com/problems/GROUPING 
Tags  anton_lunyov, cook08, medium 
Date Added:  15032011 
Time Limit:  0.499444 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 