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.

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

it's problem 241E

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

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]] ord[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:

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.