PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000107. Ứng dụng nhắn tin tức thời (Instant Messanger)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ứng dụng nhắn tin tức thời (Instant Messanger)

Instant Messanger

Source: Codeforces Version: Phuoc Hung OJ Extended

Problem Statement

An instant messaging application has nn users numbered 11 through nn. Every user is either online or offline. Friendship is an undirected relation between two different users.

Initially, some users are online and some pairs are friends. Process qq operations in order:

  • O u: User uu comes online.
  • F u: User uu goes offline.
  • A u v: Add the friendship between uu and vv.
  • D u v: Remove the friendship between uu and vv.
  • C u: Count users who are both friends of uu and currently online.

Every state-changing operation is guaranteed valid: no duplicate login, logout of an offline user, addition of an existing friendship, or deletion of a nonexistent friendship. Each change takes effect before the next operation.

Input

  • Line 1: n m q, the number of users, initial friendships, and operations.
  • Line 2: the number of initially online users o.
  • Line 3: o distinct identifiers of initially online users.
  • The next mm lines: u v, describing initial friendships without self-loops or duplicates.
  • The final qq lines contain one of O u, F u, A u v, D u v, C u.

Output

Print the number of online friends for every C u operation, one answer per line in query order.

Subtasks

  • Subtask 1 (15 points): 1≤n≤301\le n\le 30, 1≤m≤801\le m\le 80, 1≤q≤1001\le q\le 100; 1≤o≤n1\le o\le n; no initial duplicate friendships or self-loops; 1≤u,v≤n1\le u,v\le n and u≠vu\ne v for two-vertex operations; all operations satisfy their stated preconditions.
  • Subtask 2 (20 points): 1≤n≤10001\le n\le 1000, 1≤m≤25001\le m\le 2500, 1≤q≤60001\le q\le 6000; 1≤o≤n1\le o\le n; no initial duplicate friendships or self-loops; 1≤u,v≤n1\le u,v\le n and u≠vu\ne v for two-vertex operations; all operations satisfy their stated preconditions.
  • Subtask 3 (25 points): 1≤n≤100001\le n\le 10000, 1≤m≤200001\le m\le 20000, 1≤q≤600001\le q\le 60000; 1≤o≤n1\le o\le n; no initial duplicate friendships or self-loops; 1≤u,v≤n1\le u,v\le n and u≠vu\ne v for two-vertex operations; all operations satisfy their stated preconditions.
  • Subtask 4 (40 points): 1≤n≤500001\le n\le 50000, 1≤m≤1500001\le m\le 150000, 1≤q≤2500001\le q\le 250000; 1≤o≤n1\le o\le n; no initial duplicate friendships or self-loops; 1≤u,v≤n1\le u,v\le n and u≠vu\ne v for two-vertex operations; all operations satisfy their stated preconditions.

Examples

Input

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

Output

1
2
1

Explanation

Initially, only user 44 is online, with friendships (1,3)(1,3) and (3,4)(3,4); hence C 3 returns 11. After adding (2,5)(2,5), bringing user 11 online, deleting (1,3)(1,3), and adding (1,2)(1,2) and (4,2)(4,2), user 22 has friends {5,1,4}\{5,1,4\}. Users 11 and 44 are online, so C 2 returns 22. Once user 44 goes offline, only user 11 remains online among those friends, giving 11.