Problem link : CodeChef: Practical coding for everyone

My Solution : https://www.codechef.com/viewsolution/30307347

Correct solution (of @vd_patel ) : https://www.codechef.com/viewsolution/30378162

I have checked my code and vd_patel’s code on like 15-16 different input and everytime both output are same but still i am getting WA in all subtask.

so, can you please tell me where am I going wrong or any testcase where my output is wrong.

If anyone would require a little explanation of my approach then this is it :

First of all i created a list where list[i] contained all the nodes except i which means that if n=5 then list[1] will contain 2,3,4,5 and list[2] will contain 1,3,4,5 and so on.Now for each of the next k lines which is a permutation of 1 to N , I took the input in array a and removed a[j] from the list of a[i] for all j<i and I did this for all i<=n.Let’s take an example;

Suppose the permutation is : 3 2 4 1 5

Then i removed 3 from list[2]

removed 3 and 2 from list[4]

removed 3,2 and 4 from list[1]

and removed 3,2,4 and 1 from list[5]

After doing this for each one of the k lines , i iterated over all the list and counted the occurence of each element in the list.

For eg:if list[1]=5

list[2]=4,5

list[3]=2,4,1,5

list[4]=1,5

list[5]=empty

then c[1]=2(in list[3] and list[4])

c[2]=1

c[3]=0

c[4]=2

c[5]=4

then created an array flag initialised to 0

Now for each i , the answer would be the node present in list[i] with minimum count && flag[node]==0 and if the list is empty or flag of all the elements is 1 then answer will be 0 and will set the flag[ans]=1

Bit of spamming got me this test case

```
1
20 2
18 9 8 7 17 20 4 3 1 12 2 13 10 14 5 16 11 15 19 6
20 3 4 10 19 7 11 12 8 18 1 6 2 15 14 5 9 17 16 13
```

Your answer

```
7
2 14 10 12 16 0 17 1 13 19 6 5 0 0 0 0 0 9 0 3
```

Correct answer

```
5
2 14 12 10 16 0 11 1 17 19 15 6 0 5 0 0 13 9 0 3
```

@everule1 Can you please help me as well.I cant figure out what is wrong with my code for CHEF DAG as it passes through every test cases which i could thought of.

Solution Link:-CodeChef: Practical coding for everyone

Your help will be highly appreciated.

Thanks in advance!

MY code gives correct output for the test case given by you.Still its getting WA verdict.

My solution is CodeChef: Practical coding for everyone.

Kindly help me with a test case

Luckily your code failed on a small test case

```
1
5 3
1 4 5 2 3
1 3 4 5 2
4 1 5 2 3
```

Your output:

```
3
5 0 0 0 2
```

correct output:

```
2
3 0 0 5 2
```

Thanks a lot!

```
1
15 3
7 10 6 15 8 2 5 4 11 3 14 1 13 12 9
13 11 9 7 15 14 8 3 6 2 1 4 5 12 10
6 14 8 15 9 12 7 1 11 2 4 3 10 5 13
```

Your output:

```
9
0 4 0 0 0 2 5 12 0 0 3 0 0 1 0
```

Correct output:

```
8
0 4 0 0 0 1 10 5 0 0 3 0 0 12 2
```

Thanks a lot Sir

is this a valid solution?

5

2 14 19 10 16 0 12 1 17 11 6 15 0 5 0 0 13 9 6 4

6 is pointed by two nodes

Yes.