PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000044. Bạn bè tiềm năng (Possible Friends)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bạn bè tiềm năng (Possible Friends)
Possible Friends
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Two non-friends are potential friends if they share a direct friend. Find the person with the maximum number of potential friends; break ties by smallest ID.
Input
Integer , followed by an Y/N friendship matrix; persons are 0-indexed.
Output
Print the 0-based index of the chosen person and their potential-friend count.
Subtasks
- Subtask 1 (40 points): ; , symmetric matrix with
Non the diagonal;Yindicates direct friendship. - Subtask 2 (60 points): , symmetric matrix with
Non the diagonal;Yindicates direct friendship.
Examples
Input
3
NYN
YNY
NYN
Output
0 1
Explanation
People 0 and 2 are not friends but share person 1. Each has one potential friend; the smallest index 0 wins the tie.