Pheonix_0's blog

By Pheonix_0, 10 years ago, In English

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 :)

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
10 years ago, # |
Rev. 3   Vote: I like it +3 Vote: I do not like it

I'll just translate Endagorion's solution he explained to me.

  1. 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.

  2. 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].

  3. 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).

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can you please elaborate your point 3.I didnt get it. thnxz

  • »
    »
    10 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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]).

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Check out the code of top-5 contestants of that SRM to understand the solution more deeply.