Hi everyone, so I found this problem today, and it seems like a really obvious bipartite matching, but I've been getting TLE in it. Is there some faster way to solve it?
| # | User | Rating |
|---|---|---|
| 1 | tourist | 3188 |
| 2 | rng_58 | 2775 |
| 3 | Petr | 2746 |
| 4 | Egor | 2734 |
| 5 | yeputons | 2699 |
| 6 | peter50216 | 2682 |
| 7 | WJMZBMR | 2607 |
| 8 | dzhulgakov | 2569 |
| 9 | ivan.metelsky | 2556 |
| 10 | SergeyRogulenko | 2548 |
| # | User | Contrib. |
|---|---|---|
| 1 | I_love_ilona | 173 |
| 2 | Egor | 162 |
| 3 | Nickolas | 150 |
| 4 | Petr | 149 |
| 5 | Ripatti | 148 |
| 6 | SkidanovAlex | 145 |
| 7 | natalia | 144 |
| 8 | I_love_natalia | 143 |
| 8 | dalex | 143 |
| 10 | Zlobober | 142 |




O(VE) bipartite matching algorithm obviously gets TLE on dense graph with such limits. I think solution which runs in O(sqrt(v) * E) will pass. For example you can use "Hopcroft–Karp algorithm".
Sorry, forgot to say I used Hopcroft-Karp.
Strange... Show your code, maybe i can help. Solution with O(N ^ 2.376) exists, but i think Hopcroft-Karp must pass.
Here it is: http://pastebin.com/3RH9u4SN
Your algorithm works in O(VE) time and it isn't Hopcroft-Karp. Just try this testcase: 500 500
2 2 2 2 2 ... (500 times)
2 2 2 2 2 ... (500 times)
Copy this a few times and then add "0 0". Your algorithm will work more then 5 seconds (and will get TLE).
Thanks, I found the mistake, I was using the || operator instead of |= when updating the variable change. With this change it still isn't Hopcroft karp because i'm not taking shortest paths, but that only makes it a bit slower.
Dinnic works here, my solution accepted in 4.86 seconds.