#P17384. [PacNW 2025] Friendships
[PacNW 2025] Friendships
Problem Description
There are children in the Imaginative Child's Play Classroom (ICPC). Friendships are bidirectional but not transitive. At the beginning of the school year, no two children are friends.
Teachers sometimes give toys to well-behaved children. Initially, no child has any toys. No child may ever receive more than toys.
At times, a child wants to know the maximum number of toys owned by any other child who is not their friend. Process friendship, toy, and query events as they occur.
Input Format
The first line contains two integers and (), the number of children and the number of events. Children are numbered through .
Each of the next lines has one of the following forms:
F i j: children and become friends. They were not already friends, and .A i: child receives one toy.Q j: child asks for the maximum number of toys owned by another child who is not their friend.
No child will ever have more than toys.
Output Format
For every Q j event, output the requested maximum. If child is friends with every other child, output .
3 10
Q 1
A 2
A 1
A 2
Q 3
Q 2
F 2 3
Q 3
F 1 3
Q 3
0
2
1
1
-1