题目大意 给一棵树,每条边上有一个字符,求有多少对 \((x,y)(x<y)\),满足 \(x\) 到 \(y\) 路径上的边上的字符按顺序组成的字符串为回文串. \(1\leq n\leq 50000,1\leq x_i,y_i\leq n,z_i\in\{0,1\}\) 题解 观察一条经过重心的回文串是长什么样的 \(S\) 是一个任意的字符串,\(T\) 是一个回文串. 建出根到每个节点对应的串的AC自动机. 那么 \(x\) 这边的 \(S\) 串就是 \(x\) 对应的AC自动机节点的…