-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.cpp
69 lines (64 loc) · 1.46 KB
/
main.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/////////////////////////////////////
// Author: Gaurav Bholla //
// Institution: ASET //
/////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(long long i = a; i < (b); ++i)
#define repi(i, a, b) for(long long i = a; i >= (b); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define endl '\n'
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
ll n,k,p,x,cnt,ans=1;
cin>>n>>k;
vi graph[n];
int visited[n]={0};
rep(i,0,n)
{
cin>>p;
rep(j,0,p)
{
cin>>x;
graph[i].push_back(x);
}
}
queue<ll> Q;
Q.push(0);
visited[0]=1;
while(!Q.empty())
{
x=Q.front();
Q.pop();
unordered_map<ll,ll> cache;
rep(i,0,graph[x].size())
{
cache[graph[x][i]]=1;
}
rep(i,0,n)
{
if(!visited[i])
{ cnt=0;
rep(j,0,graph[i].size())
{
if(cache[graph[i][j]])
cnt++;
}
if(cnt>=k)
{
Q.push(i);
visited[i]=1;
ans++;
}
}
}
}
cout<<ans;
return 0;
}