|
| bool | dfs (int node, vector< vector< int > > &graph, vector< int > &color) |
| |
Definition at line 5 of file main.cpp.
◆ dfs()
| bool Solution::dfs |
( |
int |
node, |
|
|
vector< vector< int > > & |
graph, |
|
|
vector< int > & |
color |
|
) |
| |
|
inlineprivate |
Definition at line 8 of file main.cpp.
9 {
10 if (color[node] > 0)
11 return color[node] == 2;
12
13 color[node] = 1;
14 for (int neighbor : graph[node])
15 {
16 if (color[neighbor] == 2)
17 continue;
18 if (color[neighbor] == 1 || !
dfs(neighbor, graph, color))
19 return false;
20 }
21 color[node] = 2;
22 return true;
23 }
bool dfs(int node, vector< vector< int > > &graph, vector< int > &color)
References dfs().
Referenced by dfs(), and eventualSafeNodes().
◆ eventualSafeNodes()
| vector< int > Solution::eventualSafeNodes |
( |
vector< vector< int > > & |
graph | ) |
|
|
inline |
Definition at line 26 of file main.cpp.
27 {
28 int n = (int)graph.size();
29 vector<int> color(n, 0);
30
31 vector<int> result;
32 for (int i = 0; i < n; ++i)
33 {
34 if (
dfs(i, graph, color))
35 result.push_back(i);
36 }
37 return result;
38 }
References dfs().
Referenced by main().
The documentation for this class was generated from the following file: