#C8859. Social Network Log Processor

    ID: 52887 Type: Default 1000ms 256MiB

Social Network Log Processor

Social Network Log Processor

In this problem, you are given a social network with NN users and a log containing MM actions. There are three types of actions:

  1. Type 1 action: 1 u m — User uu posts a message with identifier mm.
  2. Type 2 action: 2 u v m — User uu forwards a message with identifier mm to user vv.
  3. Type 3 action: 3 u — Retrieve all messages received by user uu (in chronological order).

For every type 3 action, output a single line containing all message identifiers for the queried user separated by a single space. If the user has not received any messages, output an empty line.

Note: All numerical values and message identifiers in the input are separated by spaces.

inputFormat

The first line contains two integers NN and MM, where NN is the number of users and MM is the number of actions. Each of the following MM lines contains an action in one of the following formats:

  • 1 u m: User $u$ posts a message with identifier $m$.
  • 2 u v m: User $u$ forwards a message with identifier $m$ to user $v$.
  • 3 u: Retrieve and output all messages received by user $u$ in the order they were received.

outputFormat

For each type 3 action in the input, print a line containing the message identifiers for the requested user separated by a single space. If a user has no messages, print an empty line.## sample

5 7
1 1 101
1 2 102
2 1 3 103
1 3 104
3 3
2 2 1 105
3 1
103 104

101 105

</p>