How to solve Single Round Match 626 Round 1 — Division I, Level Two NegativeGraphDiv1 Problem statement- http://community.topcoder.com/stat?c=problem_statement&pm=13218&rd=15859 thnxz in advance :)
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
How to solve Single Round Match 626 Round 1 — Division I, Level Two NegativeGraphDiv1 Problem statement- http://community.topcoder.com/stat?c=problem_statement&pm=13218&rd=15859 thnxz in advance :)
Name |
---|
I'll just translate Endagorion's solution he explained to me.
Calculate arrays zero[i][j] — minimum cost of path from vertex i to j if no edge is inverted, one[i][j] — minimum cost of path from vertex i to j if at most 1 edge is inverted.
Denote d[k][i][j] — minimum cost of path, where at most k edges were inverted. Then, d[k][i][j] = min(d[k — 1][i][u] + one[u][j]) for u = 1..n. And our answer stores in d[charges][1][n].
Notice that above formula is matrix multiplication d[k][i][j] * one[i][j] ((min, +) instead of usual (+, *)).
So our answer is zero[i][j] * ((one[i][j]) ^ charges) that can be compute in O(logN).
Can you please elaborate your point 3.I didnt get it. thnxz
I didn't get that part too:) To multiply two matrices, for every row of first matrix and column of second matrix you compute their scalar multiplication (scalarMult = A[row][1] * B[1][column] + A[row][2] * B[2][column] + ... + A[row][n] * B[n][column]). It turns out that we can change scalar multiplication to any operation with two arrays, such that the associative property saves. In our case we can apply this operation (change all "+" in scalar multiplication to "min", and all "*" to "+":
ourOperation = min(A[row][1] + B[1][column], A[row][2] + B[2][column], ... , A[row][n] + B[n][column]).
Check out the code of top-5 contestants of that SRM to understand the solution more deeply.