Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Can you help with a problem

Правка en4, от Art.twink, 2024-04-01 13:55:06

Given an undirected graph with $$$N$$$ vertices and $$$M$$$ edges, count the number of simple paths that consist of exactly $$$7$$$ vertices.

Constraints: $$$N \leq 100 $$$ $$$M \leq \frac{N \cdot (N - 1)}{2}$$$

UPD: I've solved it by myself

Solution: Let's use meet in the middle technique and inclusion exclusion formula. We will count number of paths of length $$$4$$$ that are ending at the vertex $$$v$$$. Also we will count how many of them have vertex $$$a$$$ and so on for inclusion exclusion formula. So then we will also find all paths of length for. Let path will end at the vertex $$$v$$$ which means we can count number of paths of length $$$4$$$ that are starting at the vertex $$$v$$$ and not containing vertices that we already visited.

You can read more about meet in the middle and inclusion exclusion here:

https://usaco.guide/gold/combo?lang=cpp https://usaco.guide/gold/meet-in-the-middle?lang=cpp

Also here is my code: https://pastebin.com/RtX80cmC

Теги graphs

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский Art.twink 2024-04-01 13:55:06 722
en3 Английский Art.twink 2024-04-01 12:26:30 3 Tiny change: '\n\nUPD: I solved it' -> '\n\nUPD: I've solved it'
en2 Английский Art.twink 2024-04-01 12:25:57 30 Tiny change: ' - 1)}{2}$' -> ' - 1)}{2}$\n\nUPD: I solved it by myself'
en1 Английский Art.twink 2024-04-01 10:53:19 223 Initial revision (published)