Hello, guys! Can anyone suggest me an appropiate idea on this shortest path task: https://cses.fi/problemset/task/1203/? I have already exhausted all my efficient approaches on this topic. Any eligible answer would be appreciated! Thanks a lot!
№ | Пользователь | Рейтинг |
---|---|---|
1 | jiangly | 3898 |
2 | tourist | 3840 |
3 | orzdevinwang | 3706 |
4 | ksun48 | 3691 |
5 | jqdai0815 | 3682 |
6 | ecnerwala | 3525 |
7 | gamegame | 3477 |
8 | Benq | 3468 |
9 | Ormlis | 3381 |
10 | maroonrk | 3379 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | Dominater069 | 161 |
4 | Um_nik | 159 |
4 | atcoder_official | 159 |
6 | djm03178 | 157 |
7 | adamant | 153 |
8 | luogu_official | 151 |
9 | awoo | 149 |
10 | TheScrasse | 146 |
Hello, guys! Can anyone suggest me an appropiate idea on this shortest path task: https://cses.fi/problemset/task/1203/? I have already exhausted all my efficient approaches on this topic. Any eligible answer would be appreciated! Thanks a lot!
Название |
---|
Hello. lets call f(i, j) — shortest path from city i to city j. You have to print such cities z, that f(1, z) + f(z, n) = f(1, n).That's why all you have to do is to calulate f(1, i) and calculate f(i, n) for every i. you can calculate f(1, i) by running dijkstra from node 1 on the current graph.How to calculate f(i, n) in linear time?You just have to reverse all edges and run dijkstra from node n.
I understand what you mean, but your approach will yield all of those vertices involved in the set of shortest paths between 1 and n, won't it? The task's query actually requests only those vertices shared by all shortest paths between city 1 and n. Do you see what I mean?
If I applied your idea on the given example, I would gain that even vertex 2 belongs to the final answer, which is false, because all the vertices shared by those two shortest paths existent in our graph (1->2->3->4->5 and 1->3->4->5) are 1,3,4 and 5 respectively.
Did you mean something like this: https://pastebin.com/nt8cjsVU? This is my implementation based on your explanation, which receives Wrong Answer on 5 test cases from 13.
no, I didn't red the statement carefully.
But i came up with this idea(which got AC). let's leave only such edges (u, v) that f(1, u) + price[(u, v)] + f(v, n) = f(1, n).After that let's make every edge undirected. We have to print node v if v is articulation point or v = n or v = 1.
Articulation point using Tarjan's algorithm?
no.you can google it
СПАСИБО МНОГО ЧЕЛОВЕКА! Вы спасли мой день! ДА БЛАГОСЛОВИТ ВАС БОГ МОЙ ДРУГ!
Hi, so the solution is actually pretty straightforward.