-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCentral field.cpp
75 lines (61 loc) · 1.32 KB
/
Central field.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
//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
// Shoeb Akibul Islam
// Dept of ICE, NSTU
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii= pair<int,int>;
const int N=200005;
ll mod= 1e9+7;
struct node {
int endmark;
node* next[26 + 1];
node()
{
endmark = 0;
for (int i = 0; i < 26; i++)
next[i] = NULL;
}
} * root;
void insert(string& str, int len)
{
node* curr = root;
for (int i = 0; i < len; i++) {
int id = str[i] - 'a';
if (curr->next[id] == NULL)
curr->next[id] = new node();
curr = curr->next[id];
}
curr->endmark ++;
}
ll alabu(node* cur)
{
ll cnt = 1;
cnt += cur->endmark;
for (int i = 0; i < 26; i++)
if (cur->next[i])
cnt += alabu(cur->next[i]);
cnt++;
return cnt;
}
void solve(int tc)
{
int n; cin >> n;
root = new node();
for(int i = 0; i<n; i++){
string s; cin >> s;
insert(s, s.size());
}
cout << alabu(root) - 2<< '\n';
}
signed main()
{
int test_case=1;
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// cin >> test_case;
for(int i = 1; i <= test_case ; i++)
solve(i);
return 0;
}
/// Alhamdulillah...