Graph has 10 vertices.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
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.