There are N cooks (numbered 1 through N) and M dishes (numbered 1 through M). For each legitimate I, the I-th gourmet expert can cook dishes of precisely one sort Fi. Additionally, every gourmet specialist is a companion of K various cooks. 

At whatever point some culinary expert cooks a dish, he asks all gourmet specialists who either are his companions or ability to cook this dish to assess the dish. No gourmet specialist may assess his own dish. 

All the culinary experts are masterminded in succession from cook 1 to gourmet specialist N. Chefina will pick two substantial numbers L and R and permit the gourmet specialists L,L+1,… ,R to cook their dishes and have them assessed as portrayed previously. She needs to pick L and R so that every one of the N gourmet specialists assesses at any rate one dish. Locate the quantity of such combines. 



The main line of the info contains a solitary whole number T indicating the quantity of experiments. The portrayal of T experiments follows. 

The primary line of each experiment contains three space-isolated numbers N, M and K. 

The subsequent line contains N space-isolated whole numbers F1,F2,… ,FN. 

N lines follow. For every I (1≤i≤N), the I-th of these lines contains K space-isolated numbers D1,D2,… ,DK meaning the companions of the I-th gourmet specialist. 



For each experiment, print a solitary line containing one number ― the quantity of sets with the end goal that every gourmet specialist assesses at any rate one dish. 






1≤Fi≤M for each substantial I 

1≤Di≤N for each substantial I 

I !=Di for each legitimate I 

D1,D2,… ,DK are pairwise disticnt 

the whole of N⋅(K+1) over all experiments doesn’t surpass 2⋅106 


Model Input 

3 1

1 2 3 

6 2 1 

1 2 


Model Output 



March Long Challenge 2021 Solutions

April Long Challenge 2021 Solutions

Codechef Long Challenge Solutions

February Long Challenge 2021

1. Frog Sort Solution Codechef

2. Chef and Meetings Solution Codechef

3. Maximise Function Solution Codechef

4. Highest Divisor Solution Codechef

5. Cut the Cake Challenge Solution Codechef

6. Dream and the Multiverse Solution Codechef

7. Cell Shell Solution Codechef

8. Multiple Games Solution Codechef

9. Another Tree with Number Theory Solution Codechef

10. XOR Sums Solution Codechef

11. Prime Game Solution CodeChef

12. Team Name Solution Codechef

January Long Challenge 2021

November Challenge 2020 SOLUTION CodeChef

October Lunchtime 2020 CodeChef SOLUTIONS


Related :

Related :

Leave a Comment

error: Content is protected !!
Free Udemy Courses and Hacking Resources Join Us on TelegramClick Here