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 | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 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.