# | User | Rating |
---|---|---|

1 | tourist | 3434 |

2 | fateice | 3337 |

3 | Um_nik | 3292 |

4 | OO0OOO00O0OOO0O0…O | 3280 |

5 | Syloviaely | 3274 |

6 | Petr | 3223 |

7 | Swistakk | 3105 |

8 | mnbvmar | 3096 |

9 | yosupo | 3091 |

10 | dotorya | 3081 |

# | User | Contrib. |
---|---|---|

1 | rng_58 | 164 |

2 | tourist | 163 |

3 | csacademy | 152 |

4 | Petr | 150 |

5 | Swistakk | 149 |

6 | Um_nik | 144 |

7 | Nickolas | 142 |

8 | Vovuh | 141 |

9 | BledDest | 138 |

9 | matthew99 | 138 |

9 | PikMike | 138 |

9 | Errichto | 138 |

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/18/2018 07:45:49 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|

Direct the edge from node

vtoL_{v}and fromR_{v}tov.Now the problem becomes "How many ways are there to arrange the vertices such that the arrangement is topologically sorted."

Let

dp_{}(v,i) be how many topological sorts with the vertices fromv's subtree are there such that there are exactlyivertices behind the vertexv.Now updating the dp is easy.

I didn't understand your approach very clearly ... I have understood how you have reduced the problem to number of ways to order the vertices that are topologically sorted. But I didn't get what your dp state represents. Can you explain your dp state more clearly and the recurrence ?

This is the solution for any tree and not just binary trees.

Wow, thanks!