Belt Conveyor
Time limit5sMemory limit1024 MB
Given a tree of N tables, recover the original direction of every conveyor using at most 30 product-placement queries.
- Level
Hard8 of 10
- Topics
- Tree, Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
The factory of JOI Co., Ltd. has tables, numbered from 0 to . It also has belt conveyors, numbered from 0 to . Belt conveyor () connects table and table and carries products from one table to the other. The direction of transport is not visible. Ignoring directions, every pair of tables is connected through the conveyors.
IOI-kun is the factory director. He has forgotten the transport direction of every conveyor, so he repeats the following operations several times.
- He chooses some conveyors and reverses their transport directions.
- He chooses some tables and puts one product on each chosen table.
- For every table with a product, one of the following happens simultaneously.
- If no conveyor carries products out of the table, nothing happens.
- If one or more conveyors carry products out of the table, the product moves along one of those conveyors. It stops at that conveyor's destination and does not move anymore.
- IOI-kun checks each table for products. If a table has any, he takes all of them.
- For every conveyor reversed in step 1, IOI-kun restores its original direction.
IOI-kun wants to determine the original direction of every conveyor using at most 30 of these operations.
Constraints
All input data satisfy the following conditions.
- ().
- ().
- Ignoring directions, every pair of tables is connected through the belt conveyors.