-
Notifications
You must be signed in to change notification settings - Fork 59
/
amici2.cpp
59 lines (54 loc) · 1.02 KB
/
amici2.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
# include <fstream>
# include <algorithm>
# include <vector>
# include <queue>
# define NR 21005
using namespace std;
ifstream f("amici2.in");
ofstream g("amici2.out");
vector <int> v[NR];
queue <int> q;
int i,j,n,m,x,y,maxx,t,o,put;
int dist[NR];
void initializare()
{
for (int i=1; i<=n; ++i)
{v[i].clear(); dist[i]=0;}
}
void BFS (int k)
{
maxx=0;
q.push(k); dist[k]=1;
while (! q.empty())
{
k=q.front(); q.pop();
for (int i=0; i<v[k].size(); ++i)
if (! dist[v[k][i]])
{
dist[v[k][i]]=dist[k]+1;
q.push(v[k][i]);
maxx=max(maxx, dist[v[k][i]]);
}
}
--maxx;
}
int main ()
{
f>>t;
for (o=1; o<=t; ++o)
{
initializare();
f>>n>>m;
for (i=1; i<=m; ++i)
{
f>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
BFS (1);
put=0;
while ((1<<put)<maxx) ++put;
g<<put+1<<"\n";
}
return 0;
}