how to solve this problem ?

Revision en1, by learner_321, 2017-12-31 07:32:21

You have been two integers n and m where n is the size of the array and m is the number of the edges. The next line contains an array of size n and next m lines contains two integers x and y each which represents that there exists a bidirectional edge between x and y. We have to output the number of permutations of the array which are lucky. A permutation is said to be lucky if for every Vi in the array there exists an edge between Vi and Vi+1.

I/p: 3 2 1 2 3

1 2

2 3

o/p:

2(1-2-3 and 3-2-1)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English learner_321 2017-12-31 07:32:21 543 Initial revision (published)