Question: Data structures / trees Please use C language only Tom and Jerry are in the same house, which has n rooms with n two-way hallways



Example 1: Tom starts at room 2, while Jerry starts at room 1 . Jerry knows which way Tom will move around the triangle, and he can simply always move in the same way to avoid Tom forever. Example 2: Tom starts at room 1, while Jerry starts at room 4. Tom can go to room 4 on his first move and win, since Jerry must either go to room 1 (then he meets Tom on the hallway from 1 to 4) or stay at room 4 (then he meets Tom at room 4). So there is no strategy for Jerry to win. Input The first line of input gives the number of test cases, T(1T50). Then T test cases follow each described in the following way: 1. The first line contains three integers n,t,j(3n2105;1t,jn) separated by spaces, which indicate the number of rooms and the starting rooms of Tom and Jerry. 2. In the subsequent n lines, pairs of integers u and v(1u,vn,u=v) denote the existence of a two-way hallway linking rooms u and v. note: The rooms are connected and there is at most one hallway between two rooms. Output For each input produce one line of output. Print 1 if Jerry can escape Tom forever and 0 otherwise. Sample Input 6 321 21 32 13 414 14 12 13 23 412 12 23 24 34 711 41 21 53 46 42 75 34 853 83 51 26 68 12 Sample Output 1 0 1 0 0 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
