-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgirth.cpp
39 lines (39 loc) · 875 Bytes
/
girth.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
int girth(vector<vi> &adj)
{
int n = adj.Z;
int ans = 1e18;
REP(i,0,n)
{
vi vis(n,0);
vi dep(n);
vi par(n);
queue<int> kyou;
kyou.push(i);
dep[i] = 0;
vis[i] = 1;
par[i] = -1;
while(kyou.Z)
{
int frt = kyou.front();
kyou.pop();
for(int z : adj[frt])
{
if (z != par[frt])
{
if (vis[z])
{
ans = min(ans,dep[frt]+dep[z]+1);
}
else
{
par[z] = frt;
dep[z] = dep[frt]+1;
vis[z] = 1;
kyou.push(z);
}
}
}
}
}
return ans;
}