编程介的小学生 2017-10-14 16:59 采纳率: 20.5%
浏览 1688
已采纳

Rooted Trees Isomorphism

Description

Isomorphism is the problem of testing whether two graphs are really the same. Suppose we are given a collection of graphs and must perform some operation on each of them. If we can identify which of the graphs are duplicate, they can be discarded so as to avoid redundant work.
First we have to explain what is meant when we say two graphs are the same. Two labeled graphs G1 = (V1,E2) and G2 = (V2,E2) are identical when we can find a mapping f of the vertices of G1 to the vertices of G2 such that (x, y) is an edge of G1 if and only if (f(x), f(y)) is an edge of G2. Such a mapping is called an isomorphism.
No efficient algorithm is known for the general graph isomorphism problem, but the problem is easier to determine whether two trees are isomorphic to each other. In Figure 7, it is not hard to verify that tree T1 is isomorphic to tree T3, but T1 is not isomorphic to T2.

You are given a collection of k trees C = {T1, T2, ... , Tk} such that each Ti has exactly n nodes. The objective of the problem is to partition these trees into isomorphic (equivalent) classes such that any two trees within the same isomorphic class are isomorphic to each other.
A naive method of enumerating all possible mapping functions would require generating all possible n! different mappings. What resulted is a very time-consuming O(n!) time algorithm just to test two trees. You need to figure out a somehow clever way for solving the problem.
Input

A collection of k (n-node) trees C = {T1, T2, ... , Tk}. The inputs are just a list of integers. The first 2 integers (in a single line) represent the number of trees, k, and the size of each tree, n. Note that k can be as large as 150 and n can be as large as 100. After the two integers, there will be k lines representing the edge sets for each tree Ti; each line contains exactly n-1 pairs of integers, representing the n-1 (directed) edges of each tree. Thus, there are totally 2n-2 integers for each tree, and the total input will be 2k(n-1) integers except the first two parameters. Each tree is indexed by their appearance ordering; that is, the first line represents the tree T1, the second line is T2, ... , etc, and the last (kth) line is just Tk.
Output

For the given collection of trees, partition these trees into isomorphic (equivalent) classes such that any two trees within the same isomorphic class are isomorphic to each other. For each isomorphic class, output the indices of these isomorphic trees in a line. Suppose that there are m isomorphic classes, you need to print out m lines. For example, a line
t1 = t2 = ... = tp;
represents an isomorphic class of size p such that two trees Tti and Ttj , 1<=i, j <=p, are isomorphic to each other. For each line, output indices of those isomorphic trees in increasing order; that is, t1 < t2 < ... < tp. Further, print out these m isomorphic classes by their increasing lexical ordering; that is, by the ordering of their first indices. For example, suppose that there are 4 isomorphic classes {4, 2, 7}, {5, 1, 3}, {8, 9}, {6}. The output shall be
1 = 3 = 5 ;
2 = 4 = 7 ;
6 ;
8 = 9 ;
Sample Input

3 7
7 2 7 1 7 6 2 3 1 4 6 5
7 2 7 1 2 3 1 4 1 5 5 6
4 3 3 2 4 1 1 7 5 6 4 5
Sample Output

1 = 3 ;
2 ;

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-31 01:44
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)