| 212 | } |
| 213 | |
| 214 | public static void calc(int edge) { |
| 215 | cnta = 0; |
| 216 | int v1 = to2[edge]; |
| 217 | dfsLeft(v1, 0, 0, 0, 1); |
| 218 | sort(redKey, redPath, 1, cnta); |
| 219 | sort(blackKey, blackPath, 1, cnta); |
| 220 | for (int i = 2; i <= cnta; i++) { |
| 221 | redPath[i] = redPath[i - 1] * redPath[i] % MOD; |
| 222 | blackPath[i] = blackPath[i - 1] * blackPath[i] % MOD; |
| 223 | } |
| 224 | int v2 = to2[edge ^ 1]; |
| 225 | int red = (color2[edge] == 0 ? 1 : 0); |
| 226 | int black = (color2[edge] == 1 ? 1 : 0); |
| 227 | dfsRight(v2, 0, red, black, weight2[edge] % MOD); |
| 228 | } |
| 229 | |
| 230 | public static void getAns2(int u) { |
| 231 | int edge = getCentroidEdge(u, 0); |