Skip to content

Commit d538426

Browse files
authored
Create Readme.md
1 parent a34913b commit d538426

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • Graph/1059.All-Paths-from-Source-Lead-to-Destination
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### 1059.All-Paths-from-Source-Lead-to-Destination
2+
3+
此题的本质是用DFS来检查图内是否有环。模板如下:
4+
```
5+
bool dfs(int cur)
6+
{
7+
visited[cur] = 2;
8+
for (int next: graph[cur])
9+
{
10+
if (visited[next]==1) continue;
11+
if (visited[next]==2) return false;
12+
if (dfs(next)==false) return false;
13+
}
14+
visited[cur] = 1;
15+
return true;
16+
}
17+
```
18+
19+
另外,如果DFS到了端点节点,还要检查是否是destination。

0 commit comments

Comments
 (0)