#C2391. Maximum Follower Count in a Social Network

    ID: 45702 Type: Default 1000ms 256MiB

Maximum Follower Count in a Social Network

Maximum Follower Count in a Social Network

You are given a sequence of T events representing follow and unfollow actions in a social network. Each event is given as a string in one of the following formats:

  • follow A B — user A starts following user B.
  • unfollow A B — user A stops following user B.

Your task is to process these events sequentially and determine the maximum number of followers any user has after all events have been processed.

If there are no events or no followers, the result should be 0.

Note: You can assume that each unfollow event is valid (i.e. the user was previously following the other user) and that there are no duplicate follow actions.

The mathematical formulation can be expressed as:

\( \max_{u \in U} \{ f(u) \} \)

where \(U\) is the set of users and \(f(u)\) is the number of followers of user \(u\).

For example, given the events:

6
follow u1 u2
follow u2 u3
follow u1 u3
follow u3 u1
unfollow u1 u2
follow u2 u1

The maximum follower count is 2.

inputFormat

The input is given from standard input in the following format:

T
E1
E2
... 
ET

Where:

  • T is an integer representing the number of events.
  • Each Ei is a string describing an event in the format follow A B or unfollow A B.

outputFormat

Output a single integer to standard output: the maximum number of followers any user has after processing all events.

## sample
6
follow u1 u2
follow u2 u3
follow u1 u3
follow u3 u1
unfollow u1 u2
follow u2 u1
2