-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.cpp
72 lines (65 loc) · 1.32 KB
/
D.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
#include <bits/stdc++.h>
#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 1e5 + 5;
int n,k;
int ch[MAXN][26],rt = 1,tot = 1;
bool end[MAXN];
int sg[MAXN];
char str[MAXN];
inline void insert(char str[]){
int n = strlen(str+1),v = rt;
FOR(i,1,n){
int o = str[i]-'a';
if(!ch[v][o]) ch[v][o] = ++tot;
v = ch[v][o];
}
end[v] = 1;
}
int f[MAXN],g[MAXN];
inline void dfs(int v){
int c = 0;f[v] = 0;
FOR(i,0,25){
if(!ch[v][i]) continue;
++c;dfs(ch[v][i]);
if(!f[ch[v][i]]) f[v] = 1;
}
if(!c) f[v] = 0;
}
inline void dfs2(int v){
int c = 0;g[v] = 0;
FOR(i,0,25){
if(!ch[v][i]) continue;
++c;dfs2(ch[v][i]);
if(!g[ch[v][i]]) g[v] = 1;
}
if(!c) g[v] = 1;
}
int main(){
scanf("%d%d",&n,&k);
FOR(i,1,n){
scanf("%s",str+1);insert(str);
}
dfs(1);dfs2(1);
if(f[1]&&g[1]){
puts("First");
return 0;
}
if(f[1] && !g[1]){
puts(k&1?"First":"Second");
return 0;
}
puts("Second");
return 0;
}