1
0
Fork 0

Update ac-automaton.cc

This commit is contained in:
Ariel 2024-01-19 18:24:40 +08:00 committed by GitHub
parent deb343e072
commit 2ae8b3c49a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -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];
} }