-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticulation.tex
49 lines (43 loc) · 1 KB
/
articulation.tex
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
\subsection{Bruecken - Artikulationspunkte}
\begin{lstlisting}
vector<bool> visited;
int counter = 0;
vector<int> id;
vector<int> back;
vector<vector<int> > g;
int n,m;
void dfs(int v, int parent) {
visited[v] = true;
id[v] = counter++;
back[v] = id[v];
for(int i = 0; i < g[v].size(); ++i) {
int w = g[v][i];
if(w == parent) continue;
if(!visited[w]) { // Vorwaerts-Kante
dfs(w, v);
if(back[w] >= id[v]) cout << "Artikulationspunkt: " << v << endl;
if(back[w] > id[v]) cout << "Bruecke: " << v << "-" << w << endl;
back[v] = min(back[v], back[w]);
}
else // Rueckwaerts-Kante
back[v] = min(back[v], id[w]);
}
}
int main()
{
cin >> n >> m;
g.resize(n);
visited.resize(n, false);
back.resize(n);
id.resize(n);
for(int i = 0; i < m; ++i)
{
int a,b;
cin >> a >> b;
g[a].push_back(b);
}
for(int i = 0; i < n; ++i)
if(!visited[i])
dfs(i, -1);
}
\end{lstlisting}