Magic Show
Time limit1sMemory limit2048 MB
Alice must build a tree on n vertices so that Bob, given the tree after Catherine removes up to (n-2)/2 edges, can recover a number X up to 10^18.
- Level
Hard8 of 10
- Topics
- Graph, Math, Implementation
- Solved
- No attempts yet
Problem
Alice and Bob are famous magicians. Catherine, a wealthy woman who was interested in their remarkable feats, declared that she would give them a huge fortune if they could perform the following magic trick. The trick goes as follows:
- Step 1: Bob enters a room and is completely cut off from the outside. Bob can only communicate with Catherine. Then Alice tells Catherine a number between 2 and .
- Step 2: Catherine tells Alice a number between 1 and .
- Step 3: Alice builds a tree with exactly vertices and gives it to Catherine.
- Step 4: Catherine deletes at most edges from the tree and gives the remaining edges to Bob.
- Step 5: Bob studies the graph carefully and says the number that Catherine told Alice.
However, Alice and Bob do not think they are clever enough to pull off this trick, so they ask for your help. Write a program that implements Alice's strategy and Bob's strategy.
Constraints
.