-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTRIE.cpp
More file actions
58 lines (56 loc) · 1.19 KB
/
TRIE.cpp
File metadata and controls
58 lines (56 loc) · 1.19 KB
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
// Author : Manish Sharma
//
// Prefix Tree / Trie of alphabets
// Codeforces Contest# 260 Div 2
// http://codeforces.com/contest/456/problem/D
#include<bits/stdc++.h>
#define s(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
using namespace std;
typedef long long int ll;
char inp[100005];
int trie[100005][26],size=0;
int dpw[100005],dpl[100005];
int add(int node,char c)
{
c = c-'a';
if(trie[node][c])
return trie[node][c];
return (trie[node][c] = ++size);
}
void dfs(int node)
{
int i,isLeaf = true;
dpw[node] = dpl[node] = false;
for(i=0;i<26;i++)
{
if(!trie[node][i])continue;
isLeaf = false;
dfs(trie[node][i]);
if(!dpl[trie[node][i]])dpl[node]=true;
if(!dpw[trie[node][i]])dpw[node]=true;
}
if(isLeaf)
dpw[node] = true;
}
int main()
{
int i,n,k,l,u,j;
s(n);s(k);
memset(trie,0,sizeof(trie));
for(i=0;i<n;i++)
{
ss(inp);
l = strlen(inp);
u=0;
for(j=0;j<l;j++)
u = add(u,inp[j]);
}
dfs(0);
k = k&1;
if(dpw[0] && dpl[0])cout<<"First\n";
else if((dpl[0] && k))
cout<<"First\n";
else cout<<"Second\n";
return 0;
}