-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1076 DFS.cpp
62 lines (56 loc) · 1.04 KB
/
A1076 DFS.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
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
const int inf = 0x3fffffff;
const int maxn = 1010;
int G[maxn][maxn];
bool vis[maxn] = {false};
int n,L,k,query,t;
set<int> st;
void init(){
scanf("%d %d",&n,&L);
fill(G[0],G[0]+n*n,0);
//i表示的是用户的编号,下面的他的followers
for(int i = 1;i<=n;i++){
scanf("%d",&k);
for(int j=0;j<k;j++){
scanf("%d",&t);
//表示从i到t的消息传播情况
//i是t的听众,注意审题!!!!
G[t][i] = 1;
}
}
}
void DFS_func(int s,int cur_level){
if(cur_level > L+2){
return;
}
//只有合适的层次我才会进行insert这个点的情况
if(cur_level <= L+1){
st.insert(s);
}
vis[s] == true;
for(int i=1;i<=n;i++){
//i是s的一个听众
if(vis[i] == false && G[s][i] == 1){
DFS_func(i,cur_level+1);
// cout<<"one time"<<endl;
}
}
}
int main(){
init();
scanf("%d",&k);
for(int i=0;i<k;i++){
scanf("%d",&query);
fill(vis,vis+n,false);
st.clear();
DFS_func(query,1);
printf("%d\n",st.size()-1);
}
}