| 191 | } |
| 192 | |
| 193 | public static void dfsRight(int u, int fa, int red, int black, long path) { |
| 194 | if (u <= n) { |
| 195 | int r = lessThan(redKey, cnta, black - 2 * red); |
| 196 | int b = lessThan(blackKey, cnta, red - 2 * black); |
| 197 | if (r > 0) { |
| 198 | ans2 = ans2 * power(path, r) % MOD * redPath[r] % MOD; |
| 199 | } |
| 200 | if (b > 0) { |
| 201 | ans2 = ans2 * power(path, b) % MOD * blackPath[b] % MOD; |
| 202 | } |
| 203 | } |
| 204 | for (int e = head2[u]; e > 0; e = next2[e]) { |
| 205 | int v = to2[e]; |
| 206 | if (v != fa && !vis[e >> 1]) { |
| 207 | int nextRed = red + (color2[e] == 0 ? 1 : 0); |
| 208 | int nextBlack = black + (color2[e] == 1 ? 1 : 0); |
| 209 | dfsRight(v, u, nextRed, nextBlack, path * weight2[e] % MOD); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | public static void calc(int edge) { |
| 215 | cnta = 0; |