-
Notifications
You must be signed in to change notification settings - Fork 0
/
icpc2016C.cpp
90 lines (77 loc) · 1.8 KB
/
icpc2016C.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
struct Node {
int val;
Node* left = NULL;
Node* right = NULL;
Node() {}
Node(int z): val(z) {}
};
bool Equal(Node *a, Node *b) {
if(a == NULL && b == NULL) return true;
if ((a == NULL && b != NULL) || (a != NULL && b == NULL)) return false;
return Equal(a->left, b->left) && Equal(a->right, b->right);
}
void Delete(Node* node) {
if( node == NULL )
return;
Delete(node->left);
Delete(node->right);
node->left = NULL;
node->right = NULL;
delete node;
}
void Insert( Node* node, int value )
{
if( node->val > value ) {
if(node->left == NULL)
node->left = new Node( value );
else
Insert( node->left, value );
} else {
if(node->right == NULL) {
node->right = new Node( value );
}
else {
Insert( node->right, value );
}
}
}
int main() {
// freopen("input.txt", "r", stdin);
int N, K, val;
while(scanf("%d%d", &N, &K) != EOF) {
vector<Node*> v;
for(int n = 0; n < N; ++n) {
scanf("%d", &val);
Node *root = new Node(val);
for(int k = 1; k < K; ++k) {
scanf("%d", &val);
Insert(root, val);
}
v.push_back(root);
}
vector<Node*> unique;
for(int i = 0; i < v.size(); ++i) {
bool repeated = false;
for(int j = 0; j < unique.size(); ++j) {
if(Equal(unique[j], v[i])) {
repeated = true;
break;
}
}
if(!repeated) {
unique.push_back(v[i]);
}
}
printf("%d\n", unique.size());
for(int i = 0; i < v.size(); ++i) {
Delete(v[i]);
}
v.clear();
}
}