Update ac-automaton.cc
This commit is contained in:
parent
deb343e072
commit
2ae8b3c49a
|
@ -31,17 +31,17 @@ void solve(vector<string> ss, string t) {
|
||||||
// build fail
|
// build fail
|
||||||
vector<int> fail(last + 1);
|
vector<int> fail(last + 1);
|
||||||
vector<vector<int>> suc(last + 1);
|
vector<vector<int>> suc(last + 1);
|
||||||
deque<pair<int, int>> dq;
|
deque<int> dq;
|
||||||
for (int i = 0; i < 26; ++i) {
|
for (int i = 0; i < 26; ++i) {
|
||||||
if (trie[0][i]) dq.emplace_back(trie[0][i], trie[0][i]), suc[0].push_back(trie[0][i]);
|
if (trie[0][i]) dq.push_back(trie[0][i]), suc[0].push_back(trie[0][i]);
|
||||||
}
|
}
|
||||||
while (dq.size()) {
|
while (dq.size()) {
|
||||||
popfront(dq, c, rt);
|
int c = dq.front(); dq.pop_front();
|
||||||
for (int i = 0; i < 26; ++i) {
|
for (int i = 0; i < 26; ++i) {
|
||||||
if (trie[c][i]) {
|
if (trie[c][i]) {
|
||||||
fail[trie[c][i]] = trie[fail[c]][i];
|
fail[trie[c][i]] = trie[fail[c]][i];
|
||||||
suc[trie[fail[c]][i]].push_back(trie[c][i]);
|
suc[trie[fail[c]][i]].push_back(trie[c][i]);
|
||||||
dq.emplace_back(trie[c][i], rt);
|
dq.push_back(trie[c][i]);
|
||||||
} else {
|
} else {
|
||||||
trie[c][i] = trie[fail[c]][i];
|
trie[c][i] = trie[fail[c]][i];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue