mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
[mypy] Fix mypy error (#4524)
This commit is contained in:
parent
95862303a6
commit
4412eafaac
|
@ -1,25 +1,28 @@
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
def dfs(u):
|
def dfs(u):
|
||||||
global g, r, scc, component, visit, stack
|
global graph, reversedGraph, scc, component, visit, stack
|
||||||
if visit[u]:
|
if visit[u]:
|
||||||
return
|
return
|
||||||
visit[u] = True
|
visit[u] = True
|
||||||
for v in g[u]:
|
for v in graph[u]:
|
||||||
dfs(v)
|
dfs(v)
|
||||||
stack.append(u)
|
stack.append(u)
|
||||||
|
|
||||||
|
|
||||||
def dfs2(u):
|
def dfs2(u):
|
||||||
global g, r, scc, component, visit, stack
|
global graph, reversedGraph, scc, component, visit, stack
|
||||||
if visit[u]:
|
if visit[u]:
|
||||||
return
|
return
|
||||||
visit[u] = True
|
visit[u] = True
|
||||||
component.append(u)
|
component.append(u)
|
||||||
for v in r[u]:
|
for v in reversedGraph[u]:
|
||||||
dfs2(v)
|
dfs2(v)
|
||||||
|
|
||||||
|
|
||||||
def kosaraju():
|
def kosaraju():
|
||||||
global g, r, scc, component, visit, stack
|
global graph, reversedGraph, scc, component, visit, stack
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
dfs(i)
|
dfs(i)
|
||||||
visit = [False] * n
|
visit = [False] * n
|
||||||
|
@ -36,16 +39,16 @@ if __name__ == "__main__":
|
||||||
# n - no of nodes, m - no of edges
|
# n - no of nodes, m - no of edges
|
||||||
n, m = list(map(int, input().strip().split()))
|
n, m = list(map(int, input().strip().split()))
|
||||||
|
|
||||||
g = [[] for i in range(n)] # graph
|
graph: List[List[int]] = [[] for i in range(n)] # graph
|
||||||
r = [[] for i in range(n)] # reversed graph
|
reversedGraph: List[List[int]] = [[] for i in range(n)] # reversed graph
|
||||||
# input graph data (edges)
|
# input graph data (edges)
|
||||||
for i in range(m):
|
for i in range(m):
|
||||||
u, v = list(map(int, input().strip().split()))
|
u, v = list(map(int, input().strip().split()))
|
||||||
g[u].append(v)
|
graph[u].append(v)
|
||||||
r[v].append(u)
|
reversedGraph[v].append(u)
|
||||||
|
|
||||||
stack = []
|
stack: List[int] = []
|
||||||
visit = [False] * n
|
visit: List[bool] = [False] * n
|
||||||
scc = []
|
scc: List[int] = []
|
||||||
component = []
|
component: List[int] = []
|
||||||
print(kosaraju())
|
print(kosaraju())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user