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

Автор pk842, история, 5 лет назад, По-английски

P1 P2 P3 P4

As the round is over, the links are disabled by them.

I can only come up with a very basic brute force solution of $$$(2*N)!$$$ where for each of the order of visiting I calculate the cost and then update the answer accordingly. But as expected this even didn't pass even a single test.

Can someone please help me with some spoilers on how to proceed further with it?

Thanks!

Edit: Hello all! Why everyone is downvoting the post? Is there something wrong with it or I asked the question in a wrong way ? I find the problem difficult so I asked for help and if someone find it easy then instead of directly downvoting please explain the solution (or atleast a step towards it) and then downvote if you think it's irrelevant.

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by pk842 (previous revision, new revision, compare).

»
5 лет назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится

I think an algorithm for this can solve hamiltonian path problem. So I don't think that a polynomial time solution exists.

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

goes to all K cities one by one

if this means the cities should be visited in the order it is given in input then polynomial time algorithm does exist.

There are some inconsistencies in the statement, for example: the input description says there will be K integers in K lines, but sample gives all K integers in single line.

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

    Any hints towards solution?

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

      Find all pair shortest paths in $$$O(n^2\log n)$$$. Sum up distances between adjacent pair of nodes, and add minimum distance from a node of those $$$N-K$$$ nodes to first and last node of those $$$K$$$ nodes.

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

        how to distinguish the first and last node of $$$K$$$ nodes? Or did you mean to try all possible pairs.

        And also can you please explain "Sum up distances between adjacent pair of nodes" a little bit more?

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Off-topic : Were you eligible(exp.-wise) for interview or appeared in contest just for fun ? It was mentioned that this contest was for experienced candidates, so I didn't participate.