Confusion in Round 1051 C (div 2)

Revision en1, by pure, 2025-09-17 22:16:02

First of all I am new to trees and graphs so sorry in advance if I make any silly mistakes.

I was trying to do this question greedily as follows: I first initialized a deque res and set of integers inserted which says that certain input is already processed. for input u, v, x, y if u does not exist in inserted if x > y then I push u to front of res else to the back if v does not exist in inserted if x > y then I push v to back of res else to the front and then using res I created the vector finalres such that finalres[res[0] — 1] = n, finalres[res[1] — 1] = n — 1, ...

This approach does obivously seem wrong (eg, 1 4 1 2 2 1 3 4 2 1 1 3 2 1 ) which will give 3 2 4 1 which is wrong as 3 < 4

The code was accepted to my shock but not only that the code which I thought to be correct was not accepted. Link for accepted code: https://mirror.codeforces.com/contest/2143/submission/339152761 Link for the code which I thought should be accepted: https://mirror.codeforces.com/contest/2143/submission/339142596 The reason I think the second code should be accepted is because it passes through all the edges of a certain number before going ahead so the above issue would not be caused.

I would be grateful if anyone could help me understand what is going on.

Tags trees, doubt, need help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English pure 2025-09-17 22:16:02 1324 Initial revision (published)