CF245G.Suggested Friends
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarpus works as a programmer in a start-up social network. His boss gave his a task to develop a mechanism for determining suggested friends. Polycarpus thought much about the task and came to the folowing conclusion.
Let's say that all friendship relationships in a social network are given as m username pairs ai,bi (ai=bi) . Each pair ai,bi means that users ai and bi are friends. Friendship is symmetric, that is, if ai is friends with bi , then bi is also friends with ai . User y is a suggested friend for user x , if the following conditions are met:
- x=y ;
- x and y aren't friends;
- among all network users who meet the first two conditions, user y has most of all common friends with user x . User z is a common friend of user x and user y (z=x,z=y) , if x and z are friends, and y and z are also friends.
Your task is to help Polycarpus to implement a mechanism for determining suggested friends.
输入格式
The first line contains a single integer m (1<=m<=5000) — the number of pairs of friends in the social network. Next m lines contain pairs of names of the users who are friends with each other. The i -th line contains two space-separated names ai and bi (ai=bi) . The users' names are non-empty and consist of at most 20 uppercase and lowercase English letters.
It is guaranteed that each pair of friends occurs only once in the input. For example, the input can't contain x , y and y , x at the same time. It is guaranteed that distinct users have distinct names. It is guaranteed that each social network user has at least one friend. The last thing guarantees that each username occurs at least once in the input.
输出格式
In the first line print a single integer n — the number of network users. In next n lines print the number of suggested friends for each user. In the i -th line print the name of the user ci and the number of his suggested friends di after a space.
You can print information about the users in any order.
输入输出样例
输入#1
5 Mike Gerald Kate Mike Kate Tank Gerald Tank Gerald David
输出#1
5 Mike 1 Gerald 1 Kate 1 Tank 1 David 2
输入#2
4 valera vanya valera edik pasha valera igor valera
输出#2
5 valera 0 vanya 3 edik 3 pasha 3 igor 3
说明/提示
In the first test case consider user David. Users Mike and Tank have one common friend (Gerald) with David. User Kate has no common friends with David. That's why David's suggested friends are users Mike and Tank.