tom's blog

By tom, 9 years ago, In English

Problem for you for today's evening:

You are given DAG with N <  = 1000 vertexes and M <  = 10000 edges. Vertex 0 is starting vertex and vertex 1 is goal vertex. Set weights to edges from {1, 2} in that way that all paths from start to goal will have the same distance or print "NO" if it's not possible.

  • Vote: I like it
  • +9
  • Vote: I do not like it

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

Can I submit this problem or download tests somewhere? I have an idea, but I can't prove it.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it +21 Vote: I do not like it

    it's problem 241E

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

      A similar problem also appeared in a previous world finals where you could increase the weights on edges and you had to find the minimal increase required.

      Fare and balanced — Stockholm 2009

      https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=43&page=show_problem&problem=2450

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      Thanks, I didn't know that.

      I found pretty code from gawry2616676
      I don't understand one thing.

      How do we know which value (d[a[i]] or d[b[i]]) we should change? I understand constraints and I know it works (he got Accepted :)), but it seems to me unclear. Can anybody help me?

      Lines:

      if(d[a[i]]+2<d[b[i]])change=true,d[b[i]]=d[a[i]]+2;
      if(d[b[i]]-1<d[a[i]])change=true,d[a[i]]=d[b[i]]-1;
      
      • »
        »
        »
        »
        9 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        We change whichever value is on the right side of the inequality. The code is essentially running Bellman-Ford, so the change can be thought of as an edge relaxation.