简体   繁体   English

查找图中的指定边

[英]Finding specifig edges in a graph

I have an undirected graph which has some amount of nodes and edges. 我有一个无向图,其中有一些节点和边。

Each of the nodes is of certain color and each of the edges is of certain type, determined by the color of nodes it connects to : 每个节点具有特定的颜色,每个边缘具有特定的类型,这取决于它所连接的节点的颜色:

  • An edge connecting a red and blue node is of type red-blue. 连接红色和蓝色节点的边的类型为红蓝色。
  • Since the graph is undirected: red-blue == blue-red . 由于图形是无向的: red-blue == blue-red

I am tasked with writing the algorithm that will find all the edges that are "isolated". 我的任务是编写算法,该算法将查找所有“隔离的”边缘。

An edge is isolated when there is at least a 2 edges distance between the original edge and the next edge of the same type as the original one. 当原始边缘和与原始边缘相同类型的下一条边缘之间至少有2个边缘距离时,将隔离一条边缘。

What would be the best way to do this? 最好的方法是什么? Most likely it can be solved using breadth/depth first search, but I cannot figure out a way to connect them to this specific problem 很可能可以使用广度/深度优先搜索来解决,但是我无法找出一种方法将它们与特定问题联系起来

I´m pretty sure this would work, not sure about complexity 我很确定这行得通,不确定复杂性

For each node n:
    For each edge (n, n2) e:
        n.colors[edgeColor(e)] += 1
For each node n:
    n.colors2 = n.colors.copy()
    For each edge (n, n2) e:
        n.colors2 = mergeSum(n.colors2, n2.colors)
For each edge (n, n2) e:
   if n.colors2[edgeColor(e)] == 2 and n2.colors2[edgeColor(e)] == 2:
       isolated edge   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM