Friendships
시간 제한3초메모리 제한2048 MB
아이들이 친구가 되고 장난감을 받는 q개의 질의가 주어지며, Q 질의마다 친구가 아닌 아이가 가진 장난감 수의 최댓값을 출력한다.
문제
In the Imaginative Child's Play Classroom (ICPC) there are children. Over time, some of the children become friends. Friendship is a two way street, so if child A is a friend of child B, then child B is a friend of child A. On the other hand, friendship is not transitive. If child A is a friend with child B, and child B is friends with child C, then child A might not be friends with child C. Since its the start of a new school year, none of the children are friends with each other yet.
If a child behaves well in the classroom, the teacher will sometimes give the child a toy. Initially none of the children have any toys. The ICPC thinks that no child should have more than toys, so teachers are not allowed to give a toy to a child if they would exceed toys.
Sometimes, a child will get bored of playing with toys with their friends and would be jealous of other children that have lots of toys. The child will wonder what the maximum number of toys that a child who is not their friend has.
입력
The first line contains two integers: the number of children , and a number of queries ().
The children are numbered from to . Each query is of the following form:
F i j-- indicating that child became friends with child . It is guaranteed that child is not already friends with child , and .A i-- indicating that the teacher has given a toy to child .Q j-- indicating that the child would like to know the maximum number of toys any other child who is not their friend has.
It is guaranteed that no child will ever have more than toys.
출력
For every query of the form Q j, output a single integer , which is the maximum number of toys any other child who is not a friend of child has. If child is friends with all the other children, let .