CF398D.Instant Messanger

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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( uu ): User uu logins into aintalk and becomes online.
  2. logout( uu ): User uu logouts and becomes offline.
  3. add_friend( uu , vv ): User uu and user vv become friends. It means, uu and vv can talk with each other. The friendship is bidirectional.
  4. del_friend( uu , vv ): Unfriend user uu and user vv . It means, uu and vv cannot talk with each other from then.
  5. count_online_friends( uu ): The function returns the number of friends of user uu who are online at the moment.

Because the messenger is being tested by some users numbered from 11 to nn , 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 nn , mm and qq ( 1<=n<=500001<=n<=50000 ; 1<=m<=1500001<=m<=150000 ; 1<=q<=2500001<=q<=250000 ) — the number of users, the number of pairs of friends, and the number of queries.

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

Each of the next mm lines contains two space-separated integers aia_{i} and bib_{i} ( 1<=ai,bi<=n; aibi1<=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 qq lines describe the qq queries in the format:

  • "O uu " ( 1<=u<=n1<=u<=n ) : Call online( uu ). It is guaranteed that user uu was offline just before the function call.
  • "F uu " ( 1<=u<=n1<=u<=n ) : Call offline( uu ). It is guaranteed that user uu was online just before the function call.
  • "A uu vv " ( 1<=u,v<=n; uv1<=u,v<=n; u≠v ) : Call add_friend( u,vu,v ). It is guaranteed that these two users weren't friends just before the function call.
  • "D uu vv " ( 1<=u,v<=n; uv1<=u,v<=n; u≠v ) : Call del_friend( u,vu,v ). It is guaranteed that these two users were friends just before the function call.
  • "C uu " ( 1<=u<=n1<=u<=n ) : Call count_online_friends( uu ) and print the result in a single line.

输出格式

For each count_online_friends( uu ) 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
    
首页