这题思路太清奇了……->
1 //minamoto 2 #include3 #include 4 #include 5 #include 6 #include 7 #define ll long long 8 using namespace std; 9 inline int read(){ 10 #define num ch-'0' 11 char ch;bool flag=0;int res; 12 while(!isdigit(ch=getchar())) 13 (ch=='-')&&(flag=true); 14 for(res=num;isdigit(ch=getchar());res=res*10+num); 15 (flag)&&(res=-res); 16 #undef num 17 return res; 18 } 19 template inline bool cmax(T&a,const T&b){ return a =2;--i){ 56 p=a[i]; 57 cnt[fa[p]]+=cnt[p]; 58 son[fa[p]][s[le[p]-l[fa[p]]]]=p; 59 } 60 } 61 void mark(int u,int fa,int now,int len){ 62 if(!now) return; 63 if(len==l[now]) now=son[now][str[u]-'a']; 64 else if(s[le[now]-len]!=str[u]-'a') now=0; 65 if(!now) return; 66 ++tag[now]; 67 for(int i=head[u];i;i=Next[i]){ 68 int v=ver[i]; 69 if(v!=fa&&!vis[v]) mark(v,u,now,len+1); 70 } 71 } 72 inline void push(){ for(int i=1;i<=tot;++i) tag[a[i]]+=tag[fa[a[i]]];} 73 }sam1,sam2; 74 void findrt(int u,int fa){ 75 sz[u]=1,son[u]=0; 76 for(int i=head[u];i;i=Next[i]){ 77 int v=ver[i]; 78 if(v!=fa&&!vis[v]) 79 findrt(v,u),sz[u]+=sz[v],cmax(son[u],sz[v]); 80 } 81 cmax(son[u],size-sz[u]); 82 if(!rt||son[u]