logo AlgoBeat OnlineJudge
登录 注册

#217693. [PacNW 2025] Friendships

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

输入格式

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.

输出格式

For every Q j event, output the requested maximum. If child is friends with every other child, output .

样例

样例输入 1

3 10
Q 1
A 2
A 1
A 2
Q 3
Q 2
F 2 3
Q 3
F 1 3
Q 3

样例输出 1

0
2
1
1
-1