Блог пользователя Mysterious109

Автор Mysterious109, история, 17 месяцев назад, По-английски

Hi, I made a graph problem that I couldn't solve and I was wondering if it's solvable at all, so I'd appreciate if someone solved it (doesn't have to be solvable in the given constraints just any solution).

given a rooted weighted tree made of $$$n$$$ nodes you start from the root and go to any adjacent node you are given $$$m$$$ resturants each one will be on a node you are required to print the minimum cost to visit $$$k$$$ different resturants (you can visit an edge more than once)

$$$1\le n \le 10^5$$$, $$$m \le n$$$, $$$k \le m$$$, $$$1 \le cost \le 10^9$$$

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
17 месяцев назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Do we need to return to the root after visiting $$$k$$$ restaurants?

»
17 месяцев назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

الراجل ده بيتكلم صح

»
17 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Probably unsolvable, but for starters, you can solve for small $$$k$$$ using bitmask dp.

»
17 месяцев назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

So we have a tree with $$$m$$$ black nodes are your goal is to go through $$$k$$$ black nodes.

Consider two kinds of strategies:

  1. Go to a black vertex and start moving to an adjacent non-black node back and forth until you arrive at $$$k$$$ black nodes visited.
  2. Go to a black vertex and start moving to an adjacent black node back and forth until you arrive at $$$k$$$ black nodes visited.

The path follows one of these strategies, I leave the proof to the reader but it's a simple contradiction.

For each node precompute its distance to the root and the number of black nodes in this path with a simple DP. Now, for each black node try strategy 1 with its lower-weighted adjacent non-black node and strategy 2 with its lower-weighted adjacent black node.

»
17 месяцев назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

I guess that you meant that the rooted-tree is weighted-edge, i.e. each edge has a weight associated with walking through it one time. Is that right?

»
17 месяцев назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

I was thinking $$$dp[v][k][f] =$$$ min cost if you have to pick $$$k$$$ vertices from the subtree of $$$v$$$, and $$$f$$$ is 1 if you have to go all the way back to the root $$$v$$$ after getting the $$$k$$$ specials and $$$0$$$ if not.

Then we could solve this with a convolution on tree (similar to this problem): $$$dp[v][a + b][0] = min(dp[v][a][0] + dp[to][b][0])$$$ and $$$dp[v][a+b][1] = min(dp[v][a][1] + dp[to][b][0], dp[v][a][0] + dp[to][b][1])$$$.

This seems to be like a (min,+) convolution, which can be solved faster in this case since the $$$dp$$$ is convex, similary to this other problem, by mainting the difference $$$dp[v][a] - dp[v][a-1]$$$ and using small to large to merge this difference arrays.

»
17 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

is this the same as this problem? group link. it's was copied from some OI competitions.

  • »
    »
    17 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It is similar but this one is rooted so you have to visit some edges multiple times to achieve an answer

    • »
      »
      »
      17 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      unrooted seems to be harder than rooted, and also in that problem you can pass through an edge multiple times

      • »
        »
        »
        »
        17 месяцев назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        It's not about which is the harder version it's a totally different solution, the problem was solved in a comment above if you want to see the solution