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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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.