The Enemy of My Enemy Is My Friend!
Time limit2sMemory limit1024 MB
Given directed enemy edges added online, count users who are an enemy of an enemy of v, excluding v itself and v's direct enemies.
Problem
Winnie-the-Pooh signed up for a new social network called VLesu. Each user has a friend list and also an enemy list. Anyone can be added to an enemy list, but two conditions apply:
- If user is an enemy of user , then is not necessarily an enemy of .
- A user cannot be an enemy of themselves.
Winnie-the-Pooh spent whole days recording who became whose enemy, because he wanted to know everything happening in their forest. He believed nobody visits their enemy. He also believed an enemy's enemy is a friend, and anyone who respects their friends should visit them. He wants to know how many friends user has.
In Winnie-the-Pooh's view, user is a friend of user if:
- is an enemy of some enemy of .
- is not an enemy of .
No user is their own friend.
Input
The first line contains the number of users and the number of queries (, ).
Each of the next lines is one of two query types:
+ v u: user starts considering user an enemy.? v: find the number of friends of user in Winnie-the-Pooh's sense.
The input is guaranteed to be correct. A user never makes themselves an enemy, and no user becomes the enemy of another user more than once.
Output
For each query ? v, print the answer on a separate line.