1

given a weighted undirected graph with $N$ vertices $(N \leqslant 500)$ we start from vertex $S$ and wo go to $M$ and then we go to $T$ and then we return to $S$.

each edge in graph has weight $a_i$ at the beginning but after the first time we pass any edge that edge weight will become $b_i$. ($b_i \leqslant a_i$)

the task is to find the minimum sum of edges for this traverse.

time limit : 2 sec.

This is from Iran's IO, a contest that is finished. Source: https://quera.ir/course/assignments/4573/problems

xskxzr
  • 7,455
  • 5
  • 23
  • 46
  • Doesn't simply applying common algorithms of finding shortest path like A* or Dijkstra algorithm three times work? – xskxzr Mar 10 '18 at 09:02
  • i think i made counterexample for this idea. assume you have two shortest path from $S$ to $T$ with $a_i$ but one of them has shorter path of $b_i$ so it may be useful and be better for the next of cycle but we get in the longer one. – Ali.Mollahoseini Mar 10 '18 at 10:05
  • We compute the shortest path from $S$ to $M$, then recompute the shortest path from $M$ to $T$ according to the new weights, and so on. What's the problem of this method? – xskxzr Mar 10 '18 at 10:17
  • assume this as $a_i$ weights and vertex $0$ be $S$ and vertex $3$ be $M$and vertex $6$ be $T$ and this be $b_i$ weights then if you wrongly choose $0 -> 2 -> 3$ at your first dijkstra then your algorithm prints the wrong answer.am i right?! – Ali.Mollahoseini Mar 10 '18 at 10:39
  • What did you try? Where did you get stuck? We're happy to help you understand the concepts but just solving exercises for you is unlikely to achieve that. You might find this page helpful in improving your question. I suggest editing the question to show us what approaches you've already considered and why you've rejected them. – D.W. Mar 10 '18 at 17:24
  • actually its from iran's IO and it doesn't have answer and the contest had finished this is the source but I'm not sure anyone wants this link i also tried too many ideas to solve this but most of them failed and now i got a few answers that i'm not sure any of them is true. – Ali.Mollahoseini Mar 10 '18 at 18:20
  • @D.W. This problem seems not that easy, so I think it is understandable that one don't even know how to start. – xskxzr Mar 11 '18 at 07:56
  • @Ali.Mollahoseini, yes, we always want you to credit your sources. Yes, please show us your progress, including whatever facts you have found about the problem. Please include this in the question, so people don't have to read through the comments to find it. You can edit the question by clicking 'edit' under it. Thank you! – D.W. Mar 11 '18 at 16:27
  • I suggest you try working through some small examples by hand to get some intuition, and see if you can spot any patterns. If you can't, try some more examples. 2. Are you guaranteed that all edge weights are non-negative? (i.e., $0 \le b_i \le a_i$)
  • – D.W. Mar 11 '18 at 16:33
  • Here's one technique you can read about: https://cs.stackexchange.com/q/53192/755, https://cs.stackexchange.com/q/41925/755, https://cs.stackexchange.com/q/70757/755.
  • – D.W. Mar 11 '18 at 16:37