#K8156. Analyze Communication Patterns
Analyze Communication Patterns
Analyze Communication Patterns
You are given a log of messages where each record consists of three integers: a sender ID, a receiver ID, and a message ID. Your task is to analyze the communication patterns and determine, for each receiver, how many unique individuals have sent them messages.
Specifically, you should output each receiver’s ID along with the number of unique senders that have communicated with them, sorted in ascending order by receiver ID.
The input is read from stdin
and the output is printed to stdout
.
Note: If there are no messages, the output should be empty.
Mathematical Formulation: Let \( R \) be the set of receivers. For each receiver \( r \in R \), let \( S_r \) be the set of senders that have sent messages to \( r \). Output each pair \( (r, |S_r|) \) in ascending order of \( r \).
inputFormat
The first line contains an integer n
representing the number of message records. Each of the following n
lines contains three space-separated integers: sender ID, receiver ID, and message ID.
outputFormat
For each receiver, output a line containing two space-separated integers: the receiver's ID and the count of unique senders who have sent a message to that receiver. The receivers should be output in ascending order of their IDs.
## sample5
10 20 1
11 20 2
10 21 3
10 20 4
12 21 5
20 2
21 2
</p>