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

1 | tourist | 3509 |

2 | OO0OOO00O0OOO0O0…O | 3327 |

3 | Syloviaely | 3274 |

4 | Um_nik | 3237 |

5 | Petr | 3161 |

6 | ko_osaga | 3154 |

7 | LHiC | 3135 |

8 | Benq | 3130 |

9 | Swistakk | 3089 |

10 | dotorya | 3060 |

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

1 | Radewoosh | 185 |

2 | rng_58 | 161 |

3 | tourist | 158 |

4 | Petr | 152 |

5 | Vovuh | 150 |

5 | Swistakk | 150 |

7 | PikMike | 147 |

8 | csacademy | 146 |

9 | Errichto | 145 |

9 | Um_nik | 145 |

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/22/2018 03:34:26 (f1).

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!