spoj#MAXSET. MAXSET

MAXSET

 

Krish is teaching Ram Bubble sort .whenever kirsh swaps two elements in the array (while sorting),he ties a rope that connects both the element in the array.
find the size of the maximal set in the array in which none of the elements are connected with any other element .
eg : { 1 , 3 ,2 }
1st iteration of bubble sort :
2 and 3 swapped so tie 2 with 3 
{1 ,2,3}
2nd iteration 
{1,2,3}
3rd iteration 
{1,2,3}
now ans is 2 .since size of  the maximal set  in which none of the elements is not connected with any other element.
the possible maximal sets are {1,2} (since 1 and 2 are not tied with a rope) and {1,3}  { since 1 and 3 are not tied with the rope }
Input :
First line of input contains T  - No of test cases 
first line of each test case contains n ( 1 <= n <= 100000 )- number of elements in the array 
second line  of each test case contains n elements of the array 
output :
print the size of the maximal set ( for each test case print a 1new line ) 
example:
1
3
1 3 2 
output :
2

Ram and Sharav are good programmers  .Ram is teaching Sharav Bubble sort .whenever Ram swaps two elements in the array (while sorting),he ties a rope between the element which are swapped.

find the size of the maximal set in the array in which none of the elements are connected with any other element after the bubble sort is done .

eg : { 1 , 3 ,2 }

 

1st iteration of bubble sort :

2 and 3 swapped so tie 2 with 3 

{1 ,2,3}

2nd iteration 

{1,2,3}
no swaps in this iteration so dont tie any element with any other element 

3rd iteration 

{1,2,3}
no swaps in this iteration so dont tie any element with any other element  

after the end of bubble sort only 2 and 3 are tied together 

Answer for this example is 2 because the size of  the maximal set  in which none of the elements is not tied with any other element.

the possible maximal sets are {1,2} (since 1 and 2 are not tied with a rope) and {1,3}  { since 1 and 3 are not tied with the rope }

Possible subsets for this array are {1} , {2}, {3} ,{1,2} ,{1,3} ,{3,2} {1,3,2},{ }

out of these valid subsets are {1},{2},{3},{1,2},{1,3} In this valid subsets {1,2} and {1,3} are larger subsets .The size of both the subsets are 2 .so the answer is 2.

Input :

First line of input contains T  - No of test cases 

first line of each test case contains n ( 1 <= n <= 100000 )- number of elements in the array 

second line  of each test case contains n elements of the array 

 

output :

print the size of the maximal set ( for each test case print a 1new line ) 

 

 

example:

input : (from the example explained above )

1

3

1 3 2 

 

output :

2

Note : ropes are tied between two elements which are swapped while  executing the sort routine. (bubble sort) .we need the size of the set containing the maximum number of elements which are not connected to any other element in the set .