Advertisement

reverse directed graph reverse directed graph

阅读量:

Reverse a Directed Graph

反转有向图

问题描述
提供一个有向图,要求对其中所有边的方向进行调换,并将处理后的结果进行输出。

测试样例

复制代码
    # Input:
    A -> B, B -> C, A ->C
    # Output:
    B->A, C -> B, C -> A
    
    
    AI写代码python
    
    运行
在这里插入图片描述

参考代码示例

复制代码
    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # ---------------------
    # O(m+n) time|O(m+n) space
    # m 为顶点的个数,n为边的个数
    # ---------------------
    from collections import defaultdict
    
    class Node:
    def __init__(self, 

全部评论 (0)

还没有任何评论哟~