This is the problem. Here we can't change child order. But how you would solve this problem if we could change child order? Thanks.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
This is the problem. Here we can't change child order. But how you would solve this problem if we could change child order? Thanks.
Name |
---|
There is still a polynomial solution. No idea whether this is close to being optimal, it probably isn't, it's just the first thing that came to my mind.
We will have a memoized recursive function match(u,v) that returns whether the subtree of tree 1 rooted at u can be changed into the subtree of tree 2 rooted at v. Clearly, match(root1,root2) is what we want.
Here is what match(u,v) does: Let u1,...,ux be the children of u, and let v1,...,vy be the children of v. Make a bipartite graph where the ui are one partition, the vj are the other, and edges correspond to match(ui,vj) being true. Then, match(u,v) returns true iff this bipartite graph has a matching of size y. (The matching also tells you which subtree of u should be pruned to produce which subtree of v.)
Yes. Bipartite matching should work here. Thanks misof. Any other smart thinking is appreciable.
According to the faster time submission by gainullin.ildar there is a dynamic programming approach — edit distance with only Delete operation.
I think it's when they can change the child order, right? We're discussing about when we can't change the child order.
yes.