Problem X
Supervisor
Languages
en
is

At large companies it is often quite a lot of work to keep track of who is in charge of what. To try to make things easier, it is common to assign everyone to a supervisor, except the CEO who is their own supervisor. This works well, but then people start quitting their job and others get new jobs at the company, so all this planning has to be updated accordingly.
To save the day, a program that maintains all of this info is needed, something that can tell any given person who their supervisor is.
If an employee quits, their supervisor inherits all of their
subordinates. This means if
Input
The first line of input contains two integers
Next there are
If the line begins with a + this
means a new employee is starting whose supervisor will be
If the line starts with a - it
means that employee number
Finally if the line starts with a ? you should output the number of the
supervisor of employee
Output
For each query starting with a ? print the number of the supervisor in question on its own line.
Scoring
Group |
Points |
Constraints |
1 |
10 |
|
2 |
15 |
|
3 |
20 |
No + or - queries. |
4 |
20 |
No - queries. |
5 |
35 |
No further constraints. |
Sample Input 1 | Sample Output 1 |
---|---|
5 7 1 1 2 3 4 + 2 ? 6 - 2 ? 3 ? 6 + 4 ? 2 |
2 1 1 4 |