-
Notifications
You must be signed in to change notification settings - Fork 59
/
APMD.cpp
68 lines (66 loc) · 1.29 KB
/
APMD.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
# include <fstream>
# include <vector>
# include <algorithm>
# include <queue>
# define inf 999999999
using namespace std;
ifstream f("apdm.in");
ofstream g("apdm.out");
queue <int> q;
vector <int> v[155];
int i,j,n,m,x,y,o,maxx,minn,maxim,S;
int tata[155],ap[155],dist[155];
void BF (int k)
{
int i;
dist[k]=0; tata[k]=0; maxx=0;
q.push(k);
while (! q.empty())
{
k=q.front(); q.pop();
if (dist[k]>maxx) maxx=dist[k], S=k;
for (i=0; i<v[k].size(); ++i)
{
if (dist[k]+1<dist[v[k][i]])
{
dist[v[k][i]]=dist[k]+1;
tata[v[k][i]]=k;
q.push(v[k][i]);
}
}
}
}
void DFS (int k, int niv)
{
if (niv>maxim) maxim=niv;
ap[k]=1;
for (int i=0; i<v[k].size(); ++i)
{
if (!ap[v[k][i]] && (tata[v[k][i]]==k || v[k][i]==tata[k]))
{
DFS (v[k][i], niv+1);
}
}
}
int main ()
{
f>>n>>m;
for (i=1; i<=m; ++i)
{
f>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
minn=inf;
for (o=1; o<=n; ++o)
{
for (j=1; j<=n; ++j)
dist[j]=inf,ap[j]=0;
BF (o);
maxim=0;
DFS (S,0);
if (maxim<minn) minn=maxim;
}
g<<minn<<"\n";
return 0;
}