题目链接:https://hihocoder.com/problemset/problem/1457
注意:不能在遍历和统计入度的时候直接删除‘10’的边,这样会导致入度统计出错。
也不能用 maxlen[u] - maxlen[fa[u]] 来计算tot,因为‘10’ 边会影响结果。
#include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define pb push_back
const int N = 1e6+100;
const int mod = 1e9+7;
using namespace std;
queue<int>q;
ll dp[N<<1],tot[N<<1];
struct SAM{
int cnt,last,fa[N<<1],son[N<<1][30],l[N<<1],siz[N<<1],deg[N<<1];
SAM(){
cnt = 1;
fa[1] = 0;
last = 1;
memset(son,0,sizeof(son));
}
void ins(int x){
int u = last,now = last = ++cnt; //last不一定是cnt
l[now] = l[u]