Truth and Dare Solution

Problem

Ram and Shyam are playing a game of Truth and Dare. In this game, Shyam will ask Ram to perform tasks of two types:

  • Truth task: Ram has to truthfully answer a question.
  • Dare task: Ram has to perform a given task.

Each task is described by an integer. (If a truth task and a dare task are described by the same integer, they are still different tasks.) You are given four lists of tasks:

  • T_{r, 1}, T_{r, 2}, \dots, T_{r, t_r}: the truth tasks Ram can perform.
  • D_{r, 1}, D_{r, 2}, \dots, D_{r, d_r}: the dare tasks Ram can perform.
  • T_{s, 1}, T_{s, 2}, \dots, T_{s, t_s}: the truth tasks Shyam can ask Ram to perform.
  • D_{s, 1}, D_{s, 2}, \dots, D_{s, d_s}: the dare tasks Shyam can ask Ram to perform.

Note that the elements of these lists are not necessarily distinct, each task may be repeated any number of times in each list.

Shyam wins the game if he can find a task Ram cannot perform. Ram wins if he performs all tasks Shyam asks him to. Find the winner of the game.

Let's take an example where Ram can perform truth tasks 32 and 5 and dare tasks 2 and 100, and Shyam can give him truth tasks 2 and 3 and a dare task 100. We can see that whichever truth or dare tasks Shyam asks Ram to perform, Ram can easily perform them, so he wins. However, if Shyam can give him dare tasks 3 and 100, then Ram will not be able to perform dare task 3, so Shyam wins.

Input

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains a single integer t_r.
  • The second line contains t_r space-separated integers T_{r, 1}, T_{r, 2}, \dots, T_{r, t_r}.
  • The third line contains a single integer d_r.
  • The fourth line contains d_r space-separated integers D_{r, 1}, D_{r, 2}, \dots, D_{r, d_r}.
  • The fifth line contains a single integer t_s.
  • The sixth line contains t_s space-separated integers T_{s, 1}, T_{s, 2}, \dots, T_{s, t_s}.
  • The seventh line contains a single integer d_s.
  • The eighth line contains d_s space-separated integers D_{s, 1}, D_{s, 2}, \dots, D_{s, d_s}.

Output

For each test case, print a single line containing the string "yes" if Ram wins the game or "no" otherwise.

Constraints

  • 1 \le T \le 100
  • 1 \le t_r, d_r, t_s, d_s \le 100
  • 1 \le T_{r, i} \le 100 for each valid i
  • 1 \le D_{r, i} \le 100 for each valid i
  • 1 \le T_{s, i} \le 100 for each valid i
  • 1 \le D_{s, i} \le 100 for each valid i

Sample 1:

Input
Output
4
2
1 2
3
1 3 2
1
2
2
3 2
2
1 2
3
1 3 2
1
2
3
3 2 4
3
3 2 5
2
2 100
1
2
1
100
2
1 2
3
1 3 2
1
2
3
3 2 2
yes
no
yes
yes

Explanation:

Example case 1: Ram's truth tasks are [1, 2] and his dare tasks are [1, 3, 2]. Shyam's truth tasks are [2] and his dare tasks are [3, 2]. Ram can perform all tasks Shyam gives him.

Example case 2: Ram's truth tasks are [1, 2] and his dare tasks are [1, 3, 2]. Shyam's truth tasks are [2] and his dare tasks are [3, 2, 4]. If Shyam asks Ram to perform dare task 4, Ram will not be able to do it.






Program :


 #include <stdio.h>


int main(void)

{

int t,p,r,s,q;

    int f1=0;

    int f2=0;

    int a[100],b[100],c[100],d[100];

    scanf("%i",&t);

    while(t--)

    {

        scanf("%i",&p);

        for(int i=0;i<p;i++)

        {

           scanf("%i",&a[i]);

        }

        scanf("%i",&r);

        for(int i=0;i<r;i++)

        {

           scanf("%i",&b[i]);

        }

        scanf("%i",&s);

        for(int i=0;i<s;i++)

        {

           scanf("%i",&c[i]);

        }

        scanf("%i",&q);

        for(int i=0;i<q;i++)

        {

           scanf("%i",&d[i]);

        }

        for(int i=0;i<s;i++)

        {

            for(int j=0;j<p;j++)

            {

                if(c[i]==a[j])

                    {

                        f1++;

                        break;

                    }

            }

        }  

        for(int i=0;i<q;i++)

        {

            for(int j=0;j<r;j++)

            {

                if(d[i]==b[j])

                    {

                        f2++;

                        break;

                    }

            }

        }

        if(f1==s && f2==q)

        printf("yes\n");

        else

        printf("no\n");

        f1=0;

        f2=0;

    }

return 0;

}


Post a Comment

0 Comments