-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTREE2.cpp
60 lines (55 loc) · 1019 Bytes
/
TREE2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <algorithm>
using namespace std;
bool checkallzero(long long int arr[], long long int n) {
for (int i = 0;i < n;i++) {
if (arr[i] != 0) {
return false;
}
}
return true;
}
long long int countunique(long long int arr[], long long int n) {
long long int count = 0;
for (long long int i = 0;i < n;i++) {
while (i < n - 1 && (arr[i] == arr[i + 1] || arr[i] == 0)) {
i++;
}
count++;
}
return count;
}
int main() {
int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int *arr = new long long int [n];
for (long long int i = 0;i < n;i++) {
cin >> arr[i];
}
bool flag = true;
sort(arr, arr + n);
long long int ans = countunique(arr, n);
if (n == 1) {
if (arr[0] == 0) {
flag = false;
cout << 0 << endl;
}
}
else {
if (checkallzero(arr, n)) {
cout << 0 << endl;
flag = false;
}
}
if (flag == true) {
if (ans == 0)
cout << 1 << endl;
else
cout << ans << endl;
}
}
return 0;
}