Hi , I am interested to solve a problem and I can not find a polynomial solution . How many spanning trees are in a grid graph(N x M)?
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Hi , I am interested to solve a problem and I can not find a polynomial solution . How many spanning trees are in a grid graph(N x M)?
Название |
---|
If you're looking for an O((mn)O(1)) solution take a look at this.
Perhaps because of the special characteristics of the graph the determinant can be computed faster?
Can you explain the whole solution , please?
The answer for you question is the value of the determinant of the graph's Laplacian matrix. This matrix is computed multiplying the adjacency matrix by -1 and then adding the degree of each node on the main diagonal. Forgot to mention, after this you will have to erase the line and the column of an arbitrary vertex. You can consult this paper for proof. This will lead to a O((N * M)3) solution using Gaussian Elimination. I belive LU decomposition will work better on this kind of matrix though.
An easier particular case is when M = N.
This is the easier case? I can't even tell if this is an integer...
Let F be a field with an element ω of order n i.e. ωn = 1. Then is like . From , we can get for any integer k using Chebyshev polynomials. If the base field has no such ω, we can extend this field to
F[X] / (Xn - 1). Edit: X^n-1 probably doesn't work. Just generate some irreducible polynomial.I think, using that, we can solve the problem (taking word-size prime mod) in time. There is a similar formula for n ≠ m case which can be used to get similar time bound. I haven't implement any of these so I'm not sure if this really works.
You can use the Kirchhoff Theorem! It has the same complexity as computing the determinant of a matrix (which is polynomial, using Gaussian Elimination).
This Spoj problem is exactly what you describe :) Maze