| UTPC Contest 10-29-25 |
|---|
| Finished |
In the still darkness before dawn, when the air is heavy and the streets lie empty, a distant rhythm begins — tung… tung… tung… The sound echoes through narrow alleys, growing louder with every strike of the drum. It is the call for sahur, they say, a reminder to awaken and eat before the first light. Yet those who have heard it too late in the night whisper that sometimes the drummers are unseen, their footsteps leaving no trace, their beats coming from nowhere and everywhere at once. The tung tung tung drifts through fog and silence, a hollow heartbeat of something ancient that stirs only when the world sleeps deepest.
You lie awake, in the sleeping town of Al-Mahr, just before dawn. The air trembles with the distant tung… tung… tung… of the sahur drums. The axis-aligned alleys — narrow, twisting veins of stone — form a strange grid: some running North–South, others East–West, all shrouded in mist. The villagers whisper that when the drummers wander too far, their echo becomes trapped between the walls, circling endlessly through the crossroads.
Some say it's merely a trick of geometry, with the alleys connecting to each other, forming infinite loops where the sounds could wander endlessly. Other say it's an age old curse, where the droning sound of the drums forever torments the village.
Your task is to trace these alleys and decide: is it possible that the rhythm of tung tung tung is forever trapped in a ghastly loop among the alleys?
The first line contains $$$N$$$ the number of alleys. $$$1 \leq N \leq 10^3$$$.
The next $$$N$$$ lines contain 4 integers each, $$$x_1, y_1, x_2, y_2$$$, representing the starting and ending points of each alley. $$$1 \leq x_1, y_1, x_2, y_2 \leq 10^6 $$$
It is guaranteed that $$$x_1 = x_2$$$ or $$$y_1 = y_2$$$ for every alley.
It is also guaranteed that no two alleys overlap other than possibly an intersection.
Output "YES" if it is possible for the sound of tung tung tung to wander forever in the alleys, otherwise "NO". It is possible for the sound to wander forever in the alleys if there is an infinite path that the sound can take in the alleys where it never takes a $$$180$$$ degree turn on itself.
4 0 0 0 4 3 0 3 4 4 3 0 3 0 1 4 1
YES
Epilogue
And so, as the final alley was traced beneath the pallid moonlight, the rhythm began again — tung… tung… tung… — steady and slow, echoing between the stones. The cycle was real, not just in geometry, but in the ghostly pulse of Al-Mahr itself. The drummers' path wound endlessly through North and East, through shadow and fog, their echoes feeding on their own return. Somewhere within that labyrinth of narrow veins, the sound folded back upon itself — a perfect loop of rhythm and ruin. And when the dawn finally came, no one walked those streets, for they said the beat still lingered there, circling without rest, forever calling the sleepers of Al-Mahr to awaken… long after sahur had passed.
| Name |
|---|


