Under construction

Still being built. Things may change

The Enemy of My Enemy Is My Friend!

Time limit2sMemory limit1024 MB

Summary
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.
Level

Easy3 of 10

Topics
Graph, Hash map
Solved
No attempts yet

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:

  1. If user vv is an enemy of user uu, then uu is not necessarily an enemy of vv.
  2. 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 vv has.

In Winnie-the-Pooh's view, user uu is a friend of user vv if:

  1. uu is an enemy of some enemy of vv.
  2. uu is not an enemy of vv.

No user is their own friend.

Input

The first line contains the number of users nn and the number of queries mm (1≤n1 \le n, m≤2000m \le 2000).

Each of the next mm lines is one of two query types:

  • + v u: user vv starts considering user uu an enemy.
  • ? v: find the number of friends of user vv 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.

Examples1

  1. Example 1

    Input
    5 5
    + 1 2
    + 2 4
    + 2 5
    + 1 5
    ? 1
    
    Expected output
    1