Question: Please help me answer this simple coding question for an online judge platform . You can write the code in either Python3 or Java8 ;

Please help me answer this simple coding question for an online judge platform. You can write the code in either Python3 or Java8 ; whichever one is easier and faster. Please also provide screenshots of your output after entering the inputs; it should match the sample inputs and outputs in the question. Thank You!

Please help me answer this simple coding question for an online judge

Dominoes are lots of fun. Children like to stand the tiles on their side in long lines. When one domino falls, it knocks down the next one, which knocks down the one after that, all the way down the line. However, sometimes a domino fails to knock the next one down. In that case, we have to knock it down by hand to get the dominoes falling again. Given a set of dominoes that are knocked down by hand, your task is to determine the total number of dominoes that fall Input The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing three integers n, m, 1 no larger than 10 000, followed by m+l additional lines. The first integer n is the number of domino tiles. The domino tiles are numbered from 1 to n. Each of the m lines after the first line contains two integers a and y indicating that if domino number falls, it will cause domino number y to fall as well. Each of the following l lines contains a single integer z indicating that the domino numbered z is knocked over by hand Output For each test case, output a line containing one integer, the total number of dominoes that fall over. Sample Input 1 Sample Output 1 1 3 2 1 1 2 2 3 2 2 Dominoes are lots of fun. Children like to stand the tiles on their side in long lines. When one domino falls, it knocks down the next one, which knocks down the one after that, all the way down the line. However, sometimes a domino fails to knock the next one down. In that case, we have to knock it down by hand to get the dominoes falling again. Given a set of dominoes that are knocked down by hand, your task is to determine the total number of dominoes that fall Input The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing three integers n, m, 1 no larger than 10 000, followed by m+l additional lines. The first integer n is the number of domino tiles. The domino tiles are numbered from 1 to n. Each of the m lines after the first line contains two integers a and y indicating that if domino number falls, it will cause domino number y to fall as well. Each of the following l lines contains a single integer z indicating that the domino numbered z is knocked over by hand Output For each test case, output a line containing one integer, the total number of dominoes that fall over. Sample Input 1 Sample Output 1 1 3 2 1 1 2 2 3 2 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!