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

1 | tourist | 3539 |

2 | Radewoosh | 3464 |

3 | V--o_o--V | 3338 |

4 | Um_nik | 3307 |

5 | Petr | 3297 |

6 | ecnerwala | 3282 |

7 | LHiC | 3266 |

8 | wxhtxdy | 3264 |

9 | Vn_nV | 3182 |

10 | xyz111 | 3147 |

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

1 | Radewoosh | 207 |

2 | Errichto | 176 |

3 | neal | 158 |

3 | Ashishgup | 158 |

5 | Petr | 157 |

5 | PikMike | 157 |

7 | majk | 156 |

7 | rng_58 | 156 |

9 | Um_nik | 154 |

9 | 300iq | 154 |

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jan/16/2019 14:25:59 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

In your dfs function you are unnecessarily iterating over the used edges. You only need to start from scratch whenever you recompute the bfs function(), and not everytime.

In short

1)Make a ptr[] array (size >= number of vertices)

2)change line 75 to

`for(;ptr[u]<g[u].size();++ptr[u])`

//ptr[u] stores your position in g[u]3)Do a

`memset(ptr,0,sizeof ptr)`

after your bfs function returns truehttp://e-maxx.ru/algo/dinic

AC :) Thanks... Learned something new!!

Welcome :)

Hi!! Another question..Is Dinic's algorithm the same as Hopcroft-Karp algorithm??

Do we need to make any changes in Dinic's to make it Hopcroft-Karp?If yes,then how and in which part?

I wasn't right.

Actually, Hopcroft-Karp is an algorithm to find the maximum matching in a bipartite graph (and it has the same time complexity as Dinic's algorithm on bipartite graphs, but it's much faster in practice). You can always implement bipartite matching with Dinic's, but Hopcroft-Karp is easier to code in my opinion.

Hi!! As you said that Dinic's has the same complexity as Hopcroft-Karp for maximum matching... But am getting TLE for this problem on applying Dinic's algorithm.

My solution is this.Am i missing anything??? I read that HK is accepted in this problem..So should i conclude that HK is faster than Dinic's in general?

Dinic's has the same complexity as Hopcroft-Karp in

bipartite graphs. I guess you should do constant optimizations (because there are people who got AC with Dinic's) or change stuff such as the order of some fors (n -> 1 instead of 1 -> n). If all else fails, implement Push-Relabel (Which is a guaranteed AC with heuristics, but much painful to code).can you explain the statement

`fl=mini(fl,cap[u][to]-flow[u][to]);`

in the code.You are passing the bottleneck of one of the edge into all the childrenAnother way of changing it is just adding something like

`d[u] = 1000000000ll`

before`return 0`

in the dfs.Here is an accepted solution of your code: http://ideone.com/LBl7V9

why did that work ?? i cant understand