### tom's blog

By tom, 5 years ago,

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.

• +9

 » 5 years ago, # | ← Rev. 2 →   0 Can I submit this problem or download tests somewhere? I have an idea, but I can't prove it.
•  » » 5 years ago, # ^ |   +21 it's problem 241E
•  » » » 5 years ago, # ^ | ← Rev. 3 →   0 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 2009https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=43&page=show_problem&problem=2450
•  » » » 5 years ago, # ^ |   +8 Thanks, I didn't know that.I found pretty code from gawry — 2616676 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
•  » » » » 5 years ago, # ^ |   0 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.