ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 2034. Корованы

gio_gio What's problem with my algo??? [7] // Задача 2034. Корованы 25 окт 2014 17:36
I run 2 bfs. The first bfs starting from node S (that is caravan's distances) and the second starting from node R (that's distances from robbers). Then i recover route for caravan and on each step backward i choose node with maximum robber distance. Minimum of robber distance on the caravans path is the answer. What's wrong?
gio_gio Re: What's problem with my algo??? // Задача 2034. Корованы 26 окт 2014 16:39
I've WA on 12th test
Otrebus Re: What's problem with my algo??? [5] // Задача 2034. Корованы 8 июн 2015 18:03
It's because you can't greedily choose the node with the maximum robber distance. One of the other paths might contain a node with a smaller node distance somewhere further along. One such graph is here (this one is rather long, you probably just want to try to generate a graph that violates your greedy strategy yourself):
15 20
1 2
2 4
4 6
6 8
1 3
3 5
5 7
7 6
4 5
2 3
7 8
7 9
9 10
10 11
11 12
12 6
11 14
14 13
13 15
15 3
1 8 11

One strategy that works is to BFS backwards from the finishing vertex, and along each path you maintain the minimum robber distance. When two (or more) paths merge on some vertex, you consider the minimum of this path to be the maximum of the minimums of the two paths.
kasarino Re: What's problem with my algo??? // Задача 2034. Корованы 2 авг 2015 17:05
Otrebus, thank you for strategy !
Md. Mithun Rahman Re: What's problem with my algo??? [2] // Задача 2034. Корованы 7 ноя 2018 11:47
what will be the ans of this case, could you tell me please???
Mescalito Re: What's problem with my algo??? [1] // Задача 2034. Корованы 25 ноя 2018 00:20
3?
lodda Re: What's problem with my algo??? // Задача 2034. Корованы 16 сен 2020 21:51
i am also getting 3 for this case but wrong answer on test case #2 ..
alexocode Re: What's problem with my algo??? // Задача 2034. Корованы 2 апр 2025 18:17
That's an intersesting strategy. Now I have to find out how do you know when some paths emerge on some vertex