Can someone give some hints to this problem from cf edu. Problem : D. Minimum maximum on the Path
Regards.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Can someone give some hints to this problem from cf edu. Problem : D. Minimum maximum on the Path
Regards.
Название |
---|
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!
Can you share your dfs code
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.