版本比较
【学习笔记】AC 自动机
正文
增加 5 行删除 5 行
68 行未改动69707172737374757677225 行未改动全部展开30330430530630730730830931031131231331431531631631731831932057 行未改动378379380381382382383384385386217 行未改动全部展开60460560660760860860961061161243 行未改动68 行未改动inline void InsertString (string str) { int len = str.length(), now = 0; for (int i = 0; i < len; i ++) { int ch = str[i] - 'a'; if (!son(now, ch)) if (!son(now, ch)) son(now, ch) = ++cnt; now = son(now, ch); } return ++Ac[now].tot, void();225 行未改动全部展开}
void dfs (int u) { dfn[u] = ++ind, siz[u] = 1; for (int i = head[u]; ~i; i = E[i].nxt) for (int i = head[u]; ~i; i = E[i].nxt) dfs (E[i].to), siz[u] += siz[E[i].to];}
signed main() { ios_base::sync_with_stdio (false); cin.tie (nullptr), cout.tie (nullptr); cin >> T >> M, len = T.size(); memset (head, -1, sizeof (head)); for (int i = 1; i <= M; i ++) for (int i = 1; i <= M; i ++) cin >> que[i].x >> que[i].y, que[i].id = i; sort (que + 1, que + M + 1); Build_AC(), getFailPointer(), dfs(0); int pt = 0, now = 0, top = 0, up = 0;57 行未改动} Amt[MAXS];
struct Matt { int mat[MAXN][MAXN];
Matt() { memset (mat, -0x3f, sizeof(mat)); } Matt operator * (const Matt &s) const { Matt res = Matt(); for (int k = 0; k <= cnt; k ++) {217 行未改动全部展开 ios_base::sync_with_stdio (false); cin.tie (nullptr), cout.tie (nullptr); cin >> N >> K, cnt = ind = idx = 0; memset (head, -1, sizeof head); for (int i = 1; i <= K; i ++) for (int i = 1; i <= K; i ++) cin >> Style, InsertString(i); GetFailPointer(), dfs(0), Build (1, ind, 1); for (int i = 1; i <= K; i ++) tag[i] = true, Modify (dfn[tail[i]], low[tail[i]], 1, 1);43 行未改动