#SRD0000107. Ứng dụng nhắn tin tức thời (Instant Messanger)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ứ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 users numbered through . 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 operations in order:
O u: User comes online.F u: User goes offline.A u v: Add the friendship between and .D u v: Remove the friendship between and .C u: Count users who are both friends of 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:
odistinct identifiers of initially online users. - The next lines:
u v, describing initial friendships without self-loops or duplicates. - The final 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): , , ; ; no initial duplicate friendships or self-loops; and for two-vertex operations; all operations satisfy their stated preconditions.
- Subtask 2 (20 points): , , ; ; no initial duplicate friendships or self-loops; and for two-vertex operations; all operations satisfy their stated preconditions.
- Subtask 3 (25 points): , , ; ; no initial duplicate friendships or self-loops; and for two-vertex operations; all operations satisfy their stated preconditions.
- Subtask 4 (40 points): , , ; ; no initial duplicate friendships or self-loops; and 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 is online, with friendships and ; hence C 3 returns . After adding , bringing user online, deleting , and adding and , user has friends . Users and are online, so C 2 returns . Once user goes offline, only user remains online among those friends, giving .