Can someone give some hints to this problem from cf edu. Problem : D. Minimum maximum on the Path
Regards.
# | User | Rating |
---|---|---|
1 | tourist | 3856 |
2 | jiangly | 3747 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3591 |
6 | gamegame | 3477 |
7 | Benq | 3468 |
8 | Radewoosh | 3462 |
9 | ecnerwala | 3451 |
10 | heuristica | 3431 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | -is-this-fft- | 162 |
3 | Dominater069 | 160 |
4 | Um_nik | 158 |
5 | atcoder_official | 157 |
6 | Qingyu | 156 |
7 | adamant | 151 |
7 | djm03178 | 151 |
7 | luogu_official | 151 |
10 | awoo | 146 |
Can someone give some hints to this problem from cf edu. Problem : D. Minimum maximum on the Path
Regards.
Name |
---|
Binary search on the minimal possible maximum of the edges (aka answer)
If the maximum is some number x then you're only allowed to use edges with value less than or equal to x
Use a bfs on edges that satisfy the above condition to see if the final node is reachable in d edges, then reconstruct the path if it exists.
Hope that helps!
got it thanks
hey maxwellzen thanks for the hint, but how are you proving that it will be a .....1111110000.... or .....00000011111.... type of function in x.
I get this "If the maximum is some number x then you're only allowed to use edges with a value less than or equal to x" but how can we say that this x is the optimal answer, or no other x left or right to it?
If you can connect node 1 to node n in a way such that the maximum edge has a value at most x, then you guarantee that you can connect node 1 to node n in a way such that the maximum edge has a value greater than or equal to x. Therefore, the BS check function has the form ..00000111111..
can we apply dfs also ?
Yep!
I DID THE SAME BUT MY CODE KEEP GETTING REJECTED AT TEST 45 DUE TIME LIMIT, CAN YOU SHARE SOME MINOR DETAILS, I USED DFS
You are probably making too many copies of vectors. Checking if you are passing parameters by reference or as pointers in the BFS should solve it.