Can someone give some hints to this problem from cf edu. Problem : D. Minimum maximum on the Path
Regards.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 153 |
8 | awoo | 153 |
10 | luogu_official | 150 |
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.