whatthemomooofun1729's blog

By whatthemomooofun1729, history, 16 months ago, In English

Hi, I wrote this code, which basically follows the same idea as in the editorial, but I'm not sure how my code is getting WA on test case 5.

My approach is divided in two steps. The first step is to find the numbers that we can use to assign for the edges. I put these values in the array "factos." I split the input into two cases: either there are less than or equal to N-1 prime factors or there are more than N-1 prime factors. In the first case, all of the prime factors given in the input can be assigned to the edges, and for any leftover edges we can assign them a weight of 1. In the second case, we can reduce the number of prime factors by multiplying the N-M+2 greatest prime factors together, merging them into one composite number.

The second step is to find the distribution index. Using a DFS, I found the product of the number of vertices in the first component and the number of vertices in the second component (denote this as w[i]), when edge i is removed from the tree. Since this is equal to the number of distinct paths that pass through the removed edge, I multiply this amount with one of the numbers in the vector "factos", always multiplying larger values of w[i] with larger values of "factos" to get the answer.

I've read the solution several times and double checked my method and I can't seem to understand why my code gives wrong answer. My approach seems to be the same as the solution presented in the editorial. Could someone please help explain? Thank you!

Tags wa