-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBFSMismoLevel.cpp
More file actions
59 lines (54 loc) · 948 Bytes
/
BFSMismoLevel.cpp
File metadata and controls
59 lines (54 loc) · 948 Bytes
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
#include <bits/stdc++.h>
using namespace std;
vector<int> edges[10001];
bool visited[100001];
int longitud[100001];
int cantidad=0;
void inicializar()
{
for (int i=0; i<100001; i++)
{
visited[i]=false;
}
}
void funcion(int buscar)
{
queue<int> cola;
cola.push(1);
longitud[1]=1;
visited[1]=true;
while(!cola.empty())
{
int aux=cola.front();
cola.pop();
for (int i=0; i<edges[aux].size(); i++)
{
if (visited[edges[aux][i]]!=true)
{
visited[edges[aux][i]]=true;
cola.push(edges[aux][i]);
longitud[edges[aux][i]]=longitud[aux]+1;
if (longitud[edges[aux][i]]==buscar)
{
cantidad++;
}
}
}
}
}
int main()
{
inicializar();
int n=0, a=0, b=0, buscar=0;
cin>>n;
for (int i=0; i<n-1; i++)
{
cin>>a>>b;
edges[a].push_back(b);
edges[b].push_back(a);
}
cin>>buscar;
funcion(buscar);
cout<< cantidad;
return 0;
}