Hair War
Time limit1sMemory limit1024 MB
Given a complete binary tree with N broken edges, compare a fork-splitting search against a left-first DFS with return costs, and report which finishes faster.
- Level
Medium5 of 10
- Topics
- Tree, DFS, Simulation
- Solved
- No attempts yet
Problem
Blobs have always sought novelty. This time, the blobs wanted a new feel, so they prayed to the sky every day.
Tokka heard the prayers and gave the blobs twin-tail hair, and the blobs entered the Great Twin-Tail Era.

Twin-tail blob
Some blobs wanted an even newer hairstyle, so they tied their hair up and became ponytail blobs.

Twin-tail blobs grieving the arrival of ponytail blobs
At first, ponytail blobs were brushed off as strange blobs. But their number grew one by one until it was close to the number of twin-tail blobs.
The twin-tail blobs and ponytail blobs came to hate each other more and more, and the Hair War broke out!
The blobs love peace, so instead of a bloody war, they agreed to a contest of skill. Tokka chose the Twin-Tail Cave as the venue. The cave was once the main mining site of the blobs. When mining was active, it was a complete binary tree from the entrance down to depth , with rooms in total. A passage connected room and room for .
However, mining declined and the cave has been unused for a long time. passages are broken, and they cannot be traveled for the search.
Still, the war had to be fought. They decided that the faction that searches all rooms except the unreachable ones fastest wins.
By default, moving from one room to an adjacent room takes for a blob. The twin-tail and ponytail blobs chose different search methods.
Whenever twin-tail blobs reach a fork, they split their force in half and search. A force can be split at any time, since there are always enough blobs to split. But each split increases the time to move between adjacent rooms by for the split group.
The twin-tail blobs search simultaneously, so their search time is the total time of the team that took the longest.
Ponytail blobs search together in one direction. At a fork, they go left first. When there are no more rooms to search, they go back up. Note that this also costs of search time.
Each blob's clock advances only by the search time of each passage it traverses, and other time is ignored. The search ends as soon as all rooms are searched.
The figure below shows the twin-tail blobs' method on the left and the ponytail blobs' method on the right.
The war is declared and the search begins! Find which faction wins this war.
Input
The first line contains four integers , , , and , separated by spaces. They are the depth of the deepest room of the cave, the number of broken passages, the default search time of each blob faction, and the extra time added to a twin-tail group each time it splits.
All of , , , and are integers.
From the second line, the next lines each contain , the endpoints of a broken passage, separated by a space. No passage appears more than once.
Output
If the twin-tail blobs finish the search faster, print :blob_twintail_aww:. If the ponytail blobs finish faster, print :blob_twintail_sad:.
If both blobs finish the search at the same time, print :blob_twintail_thinking:.