| 80 | build_tree(); |
| 81 | } |
| 82 | long long cnt(int i) { //number of times i-th node occurs in the string |
| 83 | if (dp[i] != -1) return dp[i]; |
| 84 | long long ret = terminal[i]; |
| 85 | for (auto &x: g[i]) ret += cnt(x); |
| 86 | return dp[i] = ret; |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | int32_t main() { |