how are we supposed to solve this problem?

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

1 | MiFaFaOvO | 3681 |

2 | tourist | 3673 |

3 | Um_nik | 3493 |

4 | apiadu | 3397 |

5 | 300iq | 3317 |

6 | maroonrk | 3250 |

7 | Benq | 3230 |

8 | LHiC | 3229 |

9 | TLE | 3223 |

10 | ecnerwala | 3216 |

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

1 | antontrygubO_o | 192 |

2 | Errichto | 185 |

3 | tourist | 182 |

4 | vovuh | 170 |

5 | pikmike | 168 |

6 | ko_osaga | 165 |

7 | Radewoosh | 164 |

8 | Um_nik | 162 |

9 | 300iq | 155 |

10 | rng_58 | 153 |

how are we supposed to solve this problem?

I was trying to solve this problem based on strongly connected components — Problem

Strongly connected components can be found using Tarjan's but I haven't studied it yet!

I tried to solve it using the following information —

- All the nodes involved in a cycle are strongly connected.
- Two cycles with atleast one node in common forms strongly connected component.

I marked all the nodes in a cycle with a 'type'. When I encounter a node with some other 'type' (which means it belongs to other cycle as well), I make the disjoint set union of the two cycles.

Is there something I'm missing in my approach?

Here's my code -CODE

I've been trying this problem on spoj but not been able to come up with a optimal solution. The statement translates to — find number of ways to divide a number 'm' into 'n' distinct positive numbers.

1<=m,n<=10^6 also, m*n<=10^6

I was thinking of applying dp, but was stuck at it because it required all the numbers to be distinct. It is obvious that for all values of 'n' around 1400 and above, answer is 0.But that didn't help me in my approach.

Can dp be applied? Or could it be solved using other method?

EDIT: Solved using dp — consider a list of numbers — 1,2,3,....n (minimum possible) and at each index i,increment all numbers (i to n) by some constant.Apply dp here. I still faced some time complexity issues — http://ideone.com/yXCYeo I had to optimise it using sieve — http://ideone.com/jpHIlR

Please let me know if you used some other method.

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/09/2020 17:43:27 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|