Graph has 10 vertices.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Graph has 10 vertices.
Name |
---|
Obviously we will have a certain number of eulerian paths between only one pair of vertices, as the degrees of the end vertices should be odd and all other degrees should be even. The problem now becomes to find the number of eulerian paths between fixed 2 vertices. Now let's add an edge between these two vertices. Well now the problem becomes to find the number of eulerian circuits in this new graph. Well it appears that the number of eulerian circuits as a problem is considered #P-complete, which means it still hasn't been solved. Are you sure your problem is that, or you missunderstood it?
I completely misunderstood the problem, We are given a graph of 10 vertices and we have to find number of "Hamiltonian" paths between any 2 vertices given by a matrix d[11][11]. What i think can be done is generate all permutations of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and check if it is a valid path and if it is a valid path, increment d[first vertex][last vertex] but this approach times out. DFS also times out because the number of edges are huge. Edited the blog post
Well this approach is too slow. To solve the problem we first will fix the end vertices.
Now consider the following dp:
DP[first vertex][current vertex][visited vertices] = number of ways to reach this state from (first vertex, first vertex, only the first vertex is visited)
, were "visited vertices" is a bitmask of the visited vertices.Then the answer for a query (x, y) — x is the first vertex and y is the last one — is DP[x][y][ 2N - 1 ].
The complexity will be which should be fast enough when N ≤ 10.
If you use a variation of traveling salesman you should be able to solve it in 2^N*N^3 You have dp[i][j][mask], where it means that you start in node i, want to end in node j and the 1s in the mask tell you which nodes you can visit.