forked from love1024/spoj-solution-with-explanation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFACEFRND.cpp
35 lines (25 loc) · 751 Bytes
/
FACEFRND.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<bits/stdc++.h>
using namespace std;
int main() {
//Variables for number of friends,friend id and number of friends of friend
int n,f,m;
//Take number of friends
cin>>n;
//Take set for unique ids
set<int> st;
//Loop over all friends
for(int i=0;i<n;i++) {
//Take friend id and number of friends of friend
cin>>f>>m;
//Insert current friend id
st.insert(f);
//Traverse all friends of friend and insert them
//Set will automatically keep the unique so no duplicate
for(int i=0;i<m;i++) {
cin>>f;
st.insert(f);
}
}
//Print friend of friends by subtracting his direct friends
cout<<st.size() - n<<endl;
}