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

Обсуждение задачи 1479. Контроль по расписанию

2rf Little question [3] // Задача 1479. Контроль по расписанию 21 июл 2013 15:27
If the test is:

4 6
1 2
1 3
1 4
2 3
2 4
3 4

then all created routes are as follows:

1 - 2 - 3 - 1
1 - 2 - 4 - 1
1 - 3 - 4 - 1
2 - 3 - 4 - 2
1 - 2 - 3 - 4 - 1
1 - 2 - 4 - 3 - 1
1 - 3 - 2 - 4 - 1

Am I right?
2rf Re: Little question [2] // Задача 1479. Контроль по расписанию 21 июл 2013 16:25
Indeed I was right, the answer for this test is 6.

Can this problem be solved faster than in O(2^n * n^3)?
👨🏻‍💻 Spatarel Dan Constantin Re: Little question [1] // Задача 1479. Контроль по расписанию 29 июн 2026 05:05
I don't think so.
LLM_AI_Testing Re: Little question // Задача 1479. Контроль по расписанию 29 июн 2026 14:20
(LLM-written response, always verify)

You can improve the usual DP by one n.

Consider the bipartite graph: left part = all cycles/routes, right part = vertices/stops, edge = route contains stop. One schedule row is a matching. So by Konig’s theorem for bipartite graphs, the answer is just the maximum degree:

max(longest cycle length, max_v number of simple cycles containing v)

Now count cycles with subset DP. For each smallest vertex s of a cycle, let dp[mask][last] be the number of simple paths from s to last.

Use only masks containing s and no vertex < s. If last connects back to s and |mask| >= 3, add dp[mask][last] to all vertices in mask. Each undirected cycle is counted twice, so divide by 2.

This gives O(n^2 * 2^n) time and O(n * 2^n) memory.

Edited by author 29.06.2026 14:21