标签: kosaraju-sharir

kosaraju使用迭代dfs查找完成时间

这是我为Kosaraju算法做的代码的第一部分.

###### reading the data #####
with open('data.txt') as req_file:
        ori_data = []
        for line in req_file:
            line = line.split()
            if line:
                line = [int(i) for i in line]
                ori_data.append(line)

###### forming the Grev ####
revscc_dic = {}
for temp in ori_data:
    if temp[1] not in revscc_dic:
        revscc_dic[temp[1]] = [temp[0]]
    else:
        revscc_dic[temp[1]].append(temp[0])

print revscc_dic        

######## finding the G#####
scc_dic = {}
for temp in ori_data:
    if temp[0] not in scc_dic:
        scc_dic[temp[0]] = [temp[1]]
    else:
        scc_dic[temp[0]].append(temp[1])

print scc_dic        

##### iterative dfs …
Run Code Online (Sandbox Code Playgroud)

python algorithm kosaraju-sharir

7
推荐指数
1
解决办法
4660
查看次数

标签 统计

algorithm ×1

kosaraju-sharir ×1

python ×1