FACEFRND - Friends of Friends

Bob uses a social networking site almost all the time. He was wondering what are Friends of Friends in that social networking site? If “X” is his friend, and “Y” is X’s friend but “Y” is not his friend, then “Y” is called his friend of friend. You have to find how many friends of friends Bob has. (Each user in that social networking site has a unique 4-digit ID number)


First line contains a integer “N” (1 <= N <= 100) the number of friends in Bob's Profile. Then follow N lines.

First Integer in each line is the ID number of Bob's friend, then an integer “M” (1 <= M <= 100) is the number of people in his friend list. Then follow M integers in that line, denoting the ID number of friends in his friend list (excluding Bob). 


Output a single integer denoting Bob's number of friends of friends.


2334 5 1256 4323 7687 3244 5678
1256 2 2334 7687
4323 5 2334 5678 6547 9766 9543


hide comments
masterchef2209: 2018-08-10 16:12:19

simple problem,becomes super easy with stl sets;

vkash: 2018-07-13 19:54:33

A piece of cake!!

kkislay20: 2018-06-17 14:52:02

Can be done using a single array also. Cakewalk!!

vivek_dwivedi: 2018-06-15 22:02:27

one set ! thats it .. do it when u r boared! ;)

Last edit: 2018-06-15 22:03:17
the_ashutosh: 2018-05-30 08:42:24

just use map..

aayushbhaskar: 2018-05-26 08:21:47

AC in one go, 0.00, no STL req! :)

Last edit: 2018-05-26 08:22:10
aakash2509: 2018-05-24 13:15:30

Can be done without STL too maintaining a visited array simply.

Remember to consider ID's 0000 0004------- 0999 also. costed me unnecessarily 3 WA's -_-

persy: 2018-05-23 09:17:20

sets and thats it.. (Y)

a161112225: 2018-05-17 11:44:05

using map 0.00

coderslegacy: 2018-04-25 20:32:59

A beautiful problem on set in stl c++

Added by:Ankit Kumar Vats
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Resource:Own Problem