#DSU0000011. Bạn bè trên mạng (Virtual Friends)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bạn bè trên mạng (Virtual Friends)
Virtual Friends
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Initially, there are no friendships. Whenever two people become friends, they belong to the same social network. People are also in the same network if they are connected through a chain of friendships. After each new friendship, report the size of the network containing the two people involved.
Input
The first line contains an integer , the number of new friendships. Each of the next lines contains the names of two people. Names contain no spaces and are case-sensitive.
Output
After each friendship, print the size of the network containing the two people, one answer per line.
Subtasks
- Subtask 1 (20 points): ; each name consists of to English letters (
A–Z,a–z). - Subtask 2 (30 points): ; each name consists of to English letters (
A–Z,a–z). - Subtask 3 (50 points): ; each name consists of to English letters (
A–Z,a–z).
Examples
Input
3
Fred Barney
Barney Betty
Betty Wilma
Output
2
3
4
Explanation
Fred and Barney form a group of 2, Betty joins it to make 3, and Wilma joins to make 4.