Submit | All submissions | Best solutions | Back to list |
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)
Input
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
Output a single integer denoting Bob's number of friends of friends.
Example
Input: 3 2334 5 1256 4323 7687 3244 5678 1256 2 2334 7687 4323 5 2334 5678 6547 9766 9543 Output: 6
Added by: | Ankit Kumar Vats |
Date: | 2011-10-20 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Own Problem |
hide comments
|
|||||||||||||
2016-01-29 17:25:22
AC in first go... Easy , no need for 2-d arrays , sorting etc. |
|||||||||||||
2016-01-29 14:48:46
Had a Compile time Error because I submitted C++ code into C Compiler Very Stupid AC in 2nd go...;) Simple with Sets. |
|||||||||||||
2016-01-24 08:32:34
pure hashing concept ! single shot AC B) No sorting, No STL, No Collections, No comparisons of array values and no extra shit ! |
|||||||||||||
2016-01-15 12:18:45
Set 'FriendsOfFriends' - Set 'Friends' = AC |
|||||||||||||
2016-01-06 14:20:05 Shantanu Banerjee
All ID's are not of 4 digits. Got 2 WA's |
|||||||||||||
2016-01-03 18:46:00
one array one try ac pretty simple :) |
|||||||||||||
2015-12-27 09:30:00
AC Easy with STL Set |
|||||||||||||
2015-12-26 01:32:09
No need of STL, sets, sorting e.t.c..Just used a simple array. Sorting that array was not needed. Keep it simple. :) |
|||||||||||||
2015-12-21 18:58:12 Junaid
Extremely easy problem....use Sets in JAVA...no need of sorting or anything..AC in one go...;) |
|||||||||||||
2015-11-29 16:58:51
used maps |