Art.twink's blog

By Art.twink, history, 7 weeks ago, In English

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

Full text and comments »

  • Vote: I like it
  • +24
  • Vote: I do not like it