测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A9455. Instant Messanger

编程题 普及/提高-

题目描述

User ainta decided to make a new instant messenger called "aintalk". With aintalk, each user can chat with other people. User ainta made the prototype of some functions to implement this thing.

1. login( $u$ ): User $u$ logins into aintalk and becomes online.
2. logout( $u$ ): User $u$ logouts and becomes offline.
3. add\_friend( $u$ , $v$ ): User $u$ and user $v$ become friends. It means, $u$ and $v$ can talk with each other. The friendship is bidirectional.
4. del\_friend( $u$ , $v$ ): Unfriend user $u$ and user $v$ . It means, $u$ and $v$ cannot talk with each other from then.
5. count\_online\_friends( $u$ ): The function returns the number of friends of user $u$ who are online at the moment.

Because the messenger is being tested by some users numbered from $1$ to $n$ , there is no register method. This means, at the beginning, some users may be online, and some users may have friends.

User ainta is going to make these functions, but before making the messenger public, he wants to know whether he is correct. Help ainta verify his code.

输入格式

The first line contains three space-separated integers $n$ , $m$ and $q$ ( $1<=n<=50000$ ; $1<=m<=150000$ ; $1<=q<=250000$ ) — the number of users, the number of pairs of friends, and the number of queries.

The second line contains an integer $o$ $(1<=o<=n)$ — the number of online users at the beginning. The third line contains $o$ space-separated integers $x_{1},x_{2},...,x_{o}$ ( $1<=x_{i}<=n$ ) — the ids of the online users. It is guaranteed that these values are distinct.

Each of the next $m$ lines contains two space-separated integers $a_{i}$ and $b_{i}$ ( $1<=a_{i},b_{i}<=n; a_{i}≠b_{i}$ ) — the ids of two users who are friends at the beginning. It is guaranteed there are no multiple friendship given in the input. Note that the friendship is bidirectional.

Next $q$ lines describe the $q$ queries in the format:

- "O $u$ " ( $1<=u<=n$ ) : Call online( $u$ ). It is guaranteed that user $u$ was offline just before the function call.
- "F $u$ " ( $1<=u<=n$ ) : Call offline( $u$ ). It is guaranteed that user $u$ was online just before the function call.
- "A $u$ $v$ " ( $1<=u,v<=n; u≠v$ ) : Call add\_friend( $u,v$ ). It is guaranteed that these two users weren't friends just before the function call.
- "D $u$ $v$ " ( $1<=u,v<=n; u≠v$ ) : Call del\_friend( $u,v$ ). It is guaranteed that these two users were friends just before the function call.
- "C $u$ " ( $1<=u<=n$ ) : Call count\_online\_friends( $u$ ) and print the result in a single line.

输出格式

For each count\_online\_friends( $u$ ) query, print the required answer in a single line.

输入输出样例

输入 #1
5 2 9
1
4
1 3
3 4
C 3
A 2 5
O 1
D 1 3
A 1 2
A 4 2
C 2
F 4
C 2
输出 #1
1
2
1
上一题 去做题 下一题