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 | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | 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 | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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.