如何找到可以在图中匹配的最大对节点的数量?
我试图在Python中找到一种方法,以在无方向的图中配对节点,以便达到最大量的节点,而没有一个节点出现不止一次。
示例:
Input1:图形带有3个节点和边缘[A,B],[A,C],[B,C]
输出1:应该为2,因为没有办法选择一个以上的边缘,因此不重复节点。
Input2:图形具有6个节点和边缘[A,B],[A,C],[A,D],[B,D],[B,E],[B,F],[C,D],[C,D], [C,F],[E,F]
输出2:应该为6,因为所有节点都可以配对。例如,具有边缘[a,b],[c,d],[e,f]。
I am trying to find a way in Python to pair up nodes in an undirected graph such that the maximal amounts of nodes is reached, while no node appears more than once.
Example:
Input1: Graph with 3 nodes and edges [A, B], [A, C], [B, C]
Output1: should be 2 because there is no way to choose more than one edge such that no node is repeated.
Input2: Graph with 6 nodes and edges [A, B], [A, C], [A, D], [B, D], [B, E], [B, F], [C, D], [C, F], [E, F]
Output2: should be 6 because all nodes can be paired. For example, with edges [A, B], [C, D], [E, F].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
N1N2是一个单个变量,该变量是NODES N1和N2之间的边缘的索引,
这是该算法的C ++实现。
输出是
该应用程序的完整代码,此处是 https://gist.github.com/jamesbremner/266E273899DF4CA2815762D4BC803474
N1N2 is a single variable indexing the edge between nodes N1 and N2
Here is a C++ implementation of this algorithm
The output is
The complete code for the application is here https://gist.github.com/JamesBremner/266e273899df4ca2815762d4bc803474