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 mm username pairs ai,bia_{i},b_{i} (aibi)(a_{i}≠b_{i}) . Each pair ai,bia_{i},b_{i} means that users aia_{i} and bib_{i} are friends. Friendship is symmetric, that is, if aia_{i} is friends with bib_{i} , then bib_{i} is also friends with aia_{i} . User yy is a suggested friend for user xx , if the following conditions are met:

  1. xyx≠y ;
  2. xx and yy aren't friends;
  3. among all network users who meet the first two conditions, user yy has most of all common friends with user xx . User zz is a common friend of user xx and user yy (zx,zy)(z≠x,z≠y) , if xx and zz are friends, and yy and zz are also friends.

Your task is to help Polycarpus to implement a mechanism for determining suggested friends.

输入格式

The first line contains a single integer mm (1<=m<=5000)(1<=m<=5000) — the number of pairs of friends in the social network. Next mm lines contain pairs of names of the users who are friends with each other. The ii -th line contains two space-separated names aia_{i} and bib_{i} (aibi)(a_{i}≠b_{i}) . 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 xx , yy and yy , xx 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 nn — the number of network users. In next nn lines print the number of suggested friends for each user. In the ii -th line print the name of the user cic_{i} and the number of his suggested friends did_{i} 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.

首页