打印两个节点间所有路径(有向图)

需求:

有向图中任意给定两个节点,输出这两个节点间所有可能经过的路径,并且进行打印。

代码如下:(这里以42个节点为例)

定义节点类:

package myutil;
import java.util.ArrayList;

public class Vertex {

    boolean wasVisited; // 是否遍历过
    public int label; // 节点名称
    ArrayList<Integer> allVisitedList;// 节点已访问过的顶点

    public void setAllVisitedList(ArrayList<Integer> allVisitedList) {
        this.allVisitedList = allVisitedList;
    }

    public ArrayList<Integer> getAllVisitedList() {
        return allVisitedList;
    }

    public boolean WasVisited() {
        return wasVisited;
    }

    public void setWasVisited(boolean wasVisited) {
        this.wasVisited = wasVisited;
    }

    public int getLabel() {
        return label;
    }

    public void setLabel(char label) {
        this.label = label;
    }

    public Vertex(int lab) // constructor
    {
        label = lab;
        wasVisited = false;
    }

    public void setVisited(int j) {
        allVisitedList.set(j, 1);

    }

}

定义图类:

package myutil;

public class Graph {

    private Vertex vertexList[]; // list of vertices
    private int adjMat[][]; // adjacency matrix

    private int nVerts;
    private static int MAX_VERTS = 42; // n个点

    int i = 0;
    int j = 0;

    public Vertex[] getVertexList() {
        return vertexList;
    }

    public int[][] getAdjMat() {
        return adjMat;
    }

    public int getN() {
        return MAX_VERTS;
    }

    public Graph(int index) {
        adjMat = new int[MAX_VERTS][MAX_VERTS]; // 邻接矩阵
        vertexList = new Vertex[MAX_VERTS]; // 顶点数组
        nVerts = 0;

        for (i = 0; i < MAX_VERTS; i++) {
            for (j = 0; j < MAX_VERTS; j++) {
                adjMat[i][j] = 0;
            }
        }

        for (int i = 0; i < 42; i++) {
            addVertex(i);
        }

        addEdge(40, 8);
        addEdge(8, 28);
        addEdge(28, 41);
        addEdge(40, 11);
        addEdge(11, 29);
        addEdge(29, 41);
        addEdge(40, 22);
        addEdge(22, 30);
        addEdge(30, 41);
        addEdge(40, 3);
        addEdge(3, 31);
        addEdge(31, 41);
        addEdge(40, 17);
        addEdge(17, 32);
        addEdge(32, 41);
        addEdge(40, 19);
        addEdge(19, 33);
        addEdge(33, 41);
        addEdge(40, 16);
        addEdge(16, 34);
        addEdge(34, 41);
        addEdge(40, 13);
        addEdge(13, 35);
        addEdge(35, 41);
        addEdge(40, 5);
        addEdge(5, 36);
        addEdge(36, 41);
        addEdge(40, 25);
        addEdge(25, 37);
        addEdge(37, 41);
        addEdge(40, 7);
        addEdge(7, 38);
        addEdge(38, 41);
        addEdge(40, 24);
        addEdge(24, 39);
        addEdge(39, 41);

        switch (index) {
        case 0:
            break;
        case 1:
            delEdge(4, 2);
            break;
        default:
            break;
        }
    }

    private void delEdge(int start, int end) {
        adjMat[start][end] = 0;
    }

    private void addEdge(int start, int end) {// 有向图,添加边
        adjMat[start][end] = 1;
        // adjMat[end][start] = 1;
    }

    public void addVertex(int lab) {
        vertexList[nVerts++] = new Vertex(lab);// 添加点
    }

    public int displayVertex(int i) {
        return vertexList[i].getLabel();
    }

    public boolean displayVertexVisited(int i) {
        return vertexList[i].WasVisited();
    }

    public void printGraph() {
        for (i = 0; i < MAX_VERTS; i++) {
            System.out.print("第" + displayVertex(i) + "个节点:" + " ");

            for (j = 0; j < MAX_VERTS; j++) {
                System.out.print(displayVertex(i) + "-" + displayVertex(j)
                        + ":" + adjMat[i][j] + " ");
            }
            System.out.println();
        }

    }

}

搜索并打印路径算法类:

package myutil;
import java.util.ArrayList;
import java.util.Stack;

public class AF {

    boolean isAF = true;
    Graph graph;
    int n;
    int start, end;
    Stack<Integer> theStack;

    private ArrayList<Integer> tempList;
    private String counterexample;

    public AF(Graph graph, int start, int end) {
        this.graph = graph;
        this.start = start;
        this.end = end;
    }

    public boolean getResult() {
        graph.printGraph();
        n = graph.getN();
        theStack = new Stack<Integer>();

        if (!isConnectable(start, end)) {
            isAF = false;
            counterexample = "节点之间没有通路";
        } else {
            for (int j = 0; j < n; j++) {
                tempList = new ArrayList<Integer>();
                for (int i = 0; i < n; i++) {
                    tempList.add(0);
                }
                graph.getVertexList()[j].setAllVisitedList(tempList);
            }

            isAF = af(start, end);
        }
        return isAF;
    }

    private boolean af(int start, int end) {
        graph.getVertexList()[start].setWasVisited(true); // mark it
        theStack.push(start); // push it

        while (!theStack.isEmpty()) {
            int v = getAdjUnvisitedVertex(theStack.peek());
            if (v == -1) // if no such vertex,
            {
                tempList = new ArrayList<Integer>();
                for (int j = 0; j < n; j++) {
                    tempList.add(0);
                }
                graph.getVertexList()[theStack.peek()]
                        .setAllVisitedList(tempList);// 把栈顶节点访问过的节点链表清空
                theStack.pop();
            } else // if it exists,
            {
                theStack.push(v); // push it
            }

            if (!theStack.isEmpty() && end == theStack.peek()) {
                graph.getVertexList()[end].setWasVisited(false); // mark it
                printTheStack(theStack);
                System.out.println();
                theStack.pop();
            }
        }

        return isAF;
    }

    // 判断连个节点是否能连通
    private boolean isConnectable(int start, int end) {
        ArrayList<Integer> queue = new ArrayList<Integer>();
        ArrayList<Integer> visited = new ArrayList<Integer>();
        queue.add(start);
        while (!queue.isEmpty()) {
            for (int j = 0; j < n; j++) {
                if (graph.getAdjMat()[start][j] == 1 && !visited.contains(j)) {
                    queue.add(j);
                }
            }
            if (queue.contains(end)) {
                return true;
            } else {
                visited.add(queue.get(0));
                queue.remove(0);
                if (!queue.isEmpty()) {
                    start = queue.get(0);
                }
            }
        }
        return false;
    }

    public String counterexample() {
        for (Integer integer : theStack) {
            counterexample += graph.displayVertex(integer);
            if (integer != theStack.peek()) {
                counterexample += "-->";
            }
        }

        return counterexample;
    }

    // 与节点v相邻,并且这个节点没有被访问到,并且这个节点不在栈中
    public int getAdjUnvisitedVertex(int v) {
        ArrayList<Integer> arrayList = graph.getVertexList()[v]
                .getAllVisitedList();
        for (int j = 0; j < n; j++) {
            if (graph.getAdjMat()[v][j] == 1 && arrayList.get(j) == 0
                    && !theStack.contains(j)) {
                graph.getVertexList()[v].setVisited(j);
                return j;
            }
        }
        return -1;
    } // end getAdjUnvisitedVertex()

    public void printTheStack(Stack<Integer> theStack2) {
        for (Integer integer : theStack2) {
            System.out.print(graph.displayVertex(integer));
            if (integer != theStack2.peek()) {
                System.out.print("-->");
            }
        }
    }

}

测试类:

package myutil;
import myutil.Graph;

public class Main {

    public static void main(String[] args) {
        //第几张图,有两张(0,1),起点序号(0-6),终点序号(0-6)
        AF operation = new AF(new Graph(0), 40, 41);
        operation.getResult();
    }
}

结果如下:

第0个节点: 0-0:0 0-1:0 0-2:0 0-3:0 0-4:0 0-5:0 0-6:0 0-7:0 0-8:0 0-9:0 0-10:0 0-11:0 0-12:0 0-13:0 0-14:0 0-15:0 0-16:0 0-17:0 0-18:0 0-19:0 0-20:0 0-21:0 0-22:0 0-23:0 0-24:0 0-25:0 0-26:0 0-27:0 0-28:0 0-29:0 0-30:0 0-31:0 0-32:0 0-33:0 0-34:0 0-35:0 0-36:0 0-37:0 0-38:0 0-39:0 0-40:0 0-41:0
第1个节点: 1-0:0 1-1:0 1-2:0 1-3:0 1-4:0 1-5:0 1-6:0 1-7:0 1-8:0 1-9:0 1-10:0 1-11:0 1-12:0 1-13:0 1-14:0 1-15:0 1-16:0 1-17:0 1-18:0 1-19:0 1-20:0 1-21:0 1-22:0 1-23:0 1-24:0 1-25:0 1-26:0 1-27:0 1-28:0 1-29:0 1-30:0 1-31:0 1-32:0 1-33:0 1-34:0 1-35:0 1-36:0 1-37:0 1-38:0 1-39:0 1-40:0 1-41:0
第2个节点: 2-0:0 2-1:0 2-2:0 2-3:0 2-4:0 2-5:0 2-6:0 2-7:0 2-8:0 2-9:0 2-10:0 2-11:0 2-12:0 2-13:0 2-14:0 2-15:0 2-16:0 2-17:0 2-18:0 2-19:0 2-20:0 2-21:0 2-22:0 2-23:0 2-24:0 2-25:0 2-26:0 2-27:0 2-28:0 2-29:0 2-30:0 2-31:0 2-32:0 2-33:0 2-34:0 2-35:0 2-36:0 2-37:0 2-38:0 2-39:0 2-40:0 2-41:0
第3个节点: 3-0:0 3-1:0 3-2:0 3-3:0 3-4:0 3-5:0 3-6:0 3-7:0 3-8:0 3-9:0 3-10:0 3-11:0 3-12:0 3-13:0 3-14:0 3-15:0 3-16:0 3-17:0 3-18:0 3-19:0 3-20:0 3-21:0 3-22:0 3-23:0 3-24:0 3-25:0 3-26:0 3-27:0 3-28:0 3-29:0 3-30:0 3-31:1 3-32:0 3-33:0 3-34:0 3-35:0 3-36:0 3-37:0 3-38:0 3-39:0 3-40:0 3-41:0
第4个节点: 4-0:0 4-1:0 4-2:0 4-3:0 4-4:0 4-5:0 4-6:0 4-7:0 4-8:0 4-9:0 4-10:0 4-11:0 4-12:0 4-13:0 4-14:0 4-15:0 4-16:0 4-17:0 4-18:0 4-19:0 4-20:0 4-21:0 4-22:0 4-23:0 4-24:0 4-25:0 4-26:0 4-27:0 4-28:0 4-29:0 4-30:0 4-31:0 4-32:0 4-33:0 4-34:0 4-35:0 4-36:0 4-37:0 4-38:0 4-39:0 4-40:0 4-41:0
第5个节点: 5-0:0 5-1:0 5-2:0 5-3:0 5-4:0 5-5:0 5-6:0 5-7:0 5-8:0 5-9:0 5-10:0 5-11:0 5-12:0 5-13:0 5-14:0 5-15:0 5-16:0 5-17:0 5-18:0 5-19:0 5-20:0 5-21:0 5-22:0 5-23:0 5-24:0 5-25:0 5-26:0 5-27:0 5-28:0 5-29:0 5-30:0 5-31:0 5-32:0 5-33:0 5-34:0 5-35:0 5-36:1 5-37:0 5-38:0 5-39:0 5-40:0 5-41:0
第6个节点: 6-0:0 6-1:0 6-2:0 6-3:0 6-4:0 6-5:0 6-6:0 6-7:0 6-8:0 6-9:0 6-10:0 6-11:0 6-12:0 6-13:0 6-14:0 6-15:0 6-16:0 6-17:0 6-18:0 6-19:0 6-20:0 6-21:0 6-22:0 6-23:0 6-24:0 6-25:0 6-26:0 6-27:0 6-28:0 6-29:0 6-30:0 6-31:0 6-32:0 6-33:0 6-34:0 6-35:0 6-36:0 6-37:0 6-38:0 6-39:0 6-40:0 6-41:0
第7个节点: 7-0:0 7-1:0 7-2:0 7-3:0 7-4:0 7-5:0 7-6:0 7-7:0 7-8:0 7-9:0 7-10:0 7-11:0 7-12:0 7-13:0 7-14:0 7-15:0 7-16:0 7-17:0 7-18:0 7-19:0 7-20:0 7-21:0 7-22:0 7-23:0 7-24:0 7-25:0 7-26:0 7-27:0 7-28:0 7-29:0 7-30:0 7-31:0 7-32:0 7-33:0 7-34:0 7-35:0 7-36:0 7-37:0 7-38:1 7-39:0 7-40:0 7-41:0
第8个节点: 8-0:0 8-1:0 8-2:0 8-3:0 8-4:0 8-5:0 8-6:0 8-7:0 8-8:0 8-9:0 8-10:0 8-11:0 8-12:0 8-13:0 8-14:0 8-15:0 8-16:0 8-17:0 8-18:0 8-19:0 8-20:0 8-21:0 8-22:0 8-23:0 8-24:0 8-25:0 8-26:0 8-27:0 8-28:1 8-29:0 8-30:0 8-31:0 8-32:0 8-33:0 8-34:0 8-35:0 8-36:0 8-37:0 8-38:0 8-39:0 8-40:0 8-41:0
第9个节点: 9-0:0 9-1:0 9-2:0 9-3:0 9-4:0 9-5:0 9-6:0 9-7:0 9-8:0 9-9:0 9-10:0 9-11:0 9-12:0 9-13:0 9-14:0 9-15:0 9-16:0 9-17:0 9-18:0 9-19:0 9-20:0 9-21:0 9-22:0 9-23:0 9-24:0 9-25:0 9-26:0 9-27:0 9-28:0 9-29:0 9-30:0 9-31:0 9-32:0 9-33:0 9-34:0 9-35:0 9-36:0 9-37:0 9-38:0 9-39:0 9-40:0 9-41:0
第10个节点: 10-0:0 10-1:0 10-2:0 10-3:0 10-4:0 10-5:0 10-6:0 10-7:0 10-8:0 10-9:0 10-10:0 10-11:0 10-12:0 10-13:0 10-14:0 10-15:0 10-16:0 10-17:0 10-18:0 10-19:0 10-20:0 10-21:0 10-22:0 10-23:0 10-24:0 10-25:0 10-26:0 10-27:0 10-28:0 10-29:0 10-30:0 10-31:0 10-32:0 10-33:0 10-34:0 10-35:0 10-36:0 10-37:0 10-38:0 10-39:0 10-40:0 10-41:0
第11个节点: 11-0:0 11-1:0 11-2:0 11-3:0 11-4:0 11-5:0 11-6:0 11-7:0 11-8:0 11-9:0 11-10:0 11-11:0 11-12:0 11-13:0 11-14:0 11-15:0 11-16:0 11-17:0 11-18:0 11-19:0 11-20:0 11-21:0 11-22:0 11-23:0 11-24:0 11-25:0 11-26:0 11-27:0 11-28:0 11-29:1 11-30:0 11-31:0 11-32:0 11-33:0 11-34:0 11-35:0 11-36:0 11-37:0 11-38:0 11-39:0 11-40:0 11-41:0
第12个节点: 12-0:0 12-1:0 12-2:0 12-3:0 12-4:0 12-5:0 12-6:0 12-7:0 12-8:0 12-9:0 12-10:0 12-11:0 12-12:0 12-13:0 12-14:0 12-15:0 12-16:0 12-17:0 12-18:0 12-19:0 12-20:0 12-21:0 12-22:0 12-23:0 12-24:0 12-25:0 12-26:0 12-27:0 12-28:0 12-29:0 12-30:0 12-31:0 12-32:0 12-33:0 12-34:0 12-35:0 12-36:0 12-37:0 12-38:0 12-39:0 12-40:0 12-41:0
第13个节点: 13-0:0 13-1:0 13-2:0 13-3:0 13-4:0 13-5:0 13-6:0 13-7:0 13-8:0 13-9:0 13-10:0 13-11:0 13-12:0 13-13:0 13-14:0 13-15:0 13-16:0 13-17:0 13-18:0 13-19:0 13-20:0 13-21:0 13-22:0 13-23:0 13-24:0 13-25:0 13-26:0 13-27:0 13-28:0 13-29:0 13-30:0 13-31:0 13-32:0 13-33:0 13-34:0 13-35:1 13-36:0 13-37:0 13-38:0 13-39:0 13-40:0 13-41:0
第14个节点: 14-0:0 14-1:0 14-2:0 14-3:0 14-4:0 14-5:0 14-6:0 14-7:0 14-8:0 14-9:0 14-10:0 14-11:0 14-12:0 14-13:0 14-14:0 14-15:0 14-16:0 14-17:0 14-18:0 14-19:0 14-20:0 14-21:0 14-22:0 14-23:0 14-24:0 14-25:0 14-26:0 14-27:0 14-28:0 14-29:0 14-30:0 14-31:0 14-32:0 14-33:0 14-34:0 14-35:0 14-36:0 14-37:0 14-38:0 14-39:0 14-40:0 14-41:0
第15个节点: 15-0:0 15-1:0 15-2:0 15-3:0 15-4:0 15-5:0 15-6:0 15-7:0 15-8:0 15-9:0 15-10:0 15-11:0 15-12:0 15-13:0 15-14:0 15-15:0 15-16:0 15-17:0 15-18:0 15-19:0 15-20:0 15-21:0 15-22:0 15-23:0 15-24:0 15-25:0 15-26:0 15-27:0 15-28:0 15-29:0 15-30:0 15-31:0 15-32:0 15-33:0 15-34:0 15-35:0 15-36:0 15-37:0 15-38:0 15-39:0 15-40:0 15-41:0
第16个节点: 16-0:0 16-1:0 16-2:0 16-3:0 16-4:0 16-5:0 16-6:0 16-7:0 16-8:0 16-9:0 16-10:0 16-11:0 16-12:0 16-13:0 16-14:0 16-15:0 16-16:0 16-17:0 16-18:0 16-19:0 16-20:0 16-21:0 16-22:0 16-23:0 16-24:0 16-25:0 16-26:0 16-27:0 16-28:0 16-29:0 16-30:0 16-31:0 16-32:0 16-33:0 16-34:1 16-35:0 16-36:0 16-37:0 16-38:0 16-39:0 16-40:0 16-41:0
第17个节点: 17-0:0 17-1:0 17-2:0 17-3:0 17-4:0 17-5:0 17-6:0 17-7:0 17-8:0 17-9:0 17-10:0 17-11:0 17-12:0 17-13:0 17-14:0 17-15:0 17-16:0 17-17:0 17-18:0 17-19:0 17-20:0 17-21:0 17-22:0 17-23:0 17-24:0 17-25:0 17-26:0 17-27:0 17-28:0 17-29:0 17-30:0 17-31:0 17-32:1 17-33:0 17-34:0 17-35:0 17-36:0 17-37:0 17-38:0 17-39:0 17-40:0 17-41:0
第18个节点: 18-0:0 18-1:0 18-2:0 18-3:0 18-4:0 18-5:0 18-6:0 18-7:0 18-8:0 18-9:0 18-10:0 18-11:0 18-12:0 18-13:0 18-14:0 18-15:0 18-16:0 18-17:0 18-18:0 18-19:0 18-20:0 18-21:0 18-22:0 18-23:0 18-24:0 18-25:0 18-26:0 18-27:0 18-28:0 18-29:0 18-30:0 18-31:0 18-32:0 18-33:0 18-34:0 18-35:0 18-36:0 18-37:0 18-38:0 18-39:0 18-40:0 18-41:0
第19个节点: 19-0:0 19-1:0 19-2:0 19-3:0 19-4:0 19-5:0 19-6:0 19-7:0 19-8:0 19-9:0 19-10:0 19-11:0 19-12:0 19-13:0 19-14:0 19-15:0 19-16:0 19-17:0 19-18:0 19-19:0 19-20:0 19-21:0 19-22:0 19-23:0 19-24:0 19-25:0 19-26:0 19-27:0 19-28:0 19-29:0 19-30:0 19-31:0 19-32:0 19-33:1 19-34:0 19-35:0 19-36:0 19-37:0 19-38:0 19-39:0 19-40:0 19-41:0
第20个节点: 20-0:0 20-1:0 20-2:0 20-3:0 20-4:0 20-5:0 20-6:0 20-7:0 20-8:0 20-9:0 20-10:0 20-11:0 20-12:0 20-13:0 20-14:0 20-15:0 20-16:0 20-17:0 20-18:0 20-19:0 20-20:0 20-21:0 20-22:0 20-23:0 20-24:0 20-25:0 20-26:0 20-27:0 20-28:0 20-29:0 20-30:0 20-31:0 20-32:0 20-33:0 20-34:0 20-35:0 20-36:0 20-37:0 20-38:0 20-39:0 20-40:0 20-41:0
第21个节点: 21-0:0 21-1:0 21-2:0 21-3:0 21-4:0 21-5:0 21-6:0 21-7:0 21-8:0 21-9:0 21-10:0 21-11:0 21-12:0 21-13:0 21-14:0 21-15:0 21-16:0 21-17:0 21-18:0 21-19:0 21-20:0 21-21:0 21-22:0 21-23:0 21-24:0 21-25:0 21-26:0 21-27:0 21-28:0 21-29:0 21-30:0 21-31:0 21-32:0 21-33:0 21-34:0 21-35:0 21-36:0 21-37:0 21-38:0 21-39:0 21-40:0 21-41:0
第22个节点: 22-0:0 22-1:0 22-2:0 22-3:0 22-4:0 22-5:0 22-6:0 22-7:0 22-8:0 22-9:0 22-10:0 22-11:0 22-12:0 22-13:0 22-14:0 22-15:0 22-16:0 22-17:0 22-18:0 22-19:0 22-20:0 22-21:0 22-22:0 22-23:0 22-24:0 22-25:0 22-26:0 22-27:0 22-28:0 22-29:0 22-30:1 22-31:0 22-32:0 22-33:0 22-34:0 22-35:0 22-36:0 22-37:0 22-38:0 22-39:0 22-40:0 22-41:0
第23个节点: 23-0:0 23-1:0 23-2:0 23-3:0 23-4:0 23-5:0 23-6:0 23-7:0 23-8:0 23-9:0 23-10:0 23-11:0 23-12:0 23-13:0 23-14:0 23-15:0 23-16:0 23-17:0 23-18:0 23-19:0 23-20:0 23-21:0 23-22:0 23-23:0 23-24:0 23-25:0 23-26:0 23-27:0 23-28:0 23-29:0 23-30:0 23-31:0 23-32:0 23-33:0 23-34:0 23-35:0 23-36:0 23-37:0 23-38:0 23-39:0 23-40:0 23-41:0
第24个节点: 24-0:0 24-1:0 24-2:0 24-3:0 24-4:0 24-5:0 24-6:0 24-7:0 24-8:0 24-9:0 24-10:0 24-11:0 24-12:0 24-13:0 24-14:0 24-15:0 24-16:0 24-17:0 24-18:0 24-19:0 24-20:0 24-21:0 24-22:0 24-23:0 24-24:0 24-25:0 24-26:0 24-27:0 24-28:0 24-29:0 24-30:0 24-31:0 24-32:0 24-33:0 24-34:0 24-35:0 24-36:0 24-37:0 24-38:0 24-39:1 24-40:0 24-41:0
第25个节点: 25-0:0 25-1:0 25-2:0 25-3:0 25-4:0 25-5:0 25-6:0 25-7:0 25-8:0 25-9:0 25-10:0 25-11:0 25-12:0 25-13:0 25-14:0 25-15:0 25-16:0 25-17:0 25-18:0 25-19:0 25-20:0 25-21:0 25-22:0 25-23:0 25-24:0 25-25:0 25-26:0 25-27:0 25-28:0 25-29:0 25-30:0 25-31:0 25-32:0 25-33:0 25-34:0 25-35:0 25-36:0 25-37:1 25-38:0 25-39:0 25-40:0 25-41:0
第26个节点: 26-0:0 26-1:0 26-2:0 26-3:0 26-4:0 26-5:0 26-6:0 26-7:0 26-8:0 26-9:0 26-10:0 26-11:0 26-12:0 26-13:0 26-14:0 26-15:0 26-16:0 26-17:0 26-18:0 26-19:0 26-20:0 26-21:0 26-22:0 26-23:0 26-24:0 26-25:0 26-26:0 26-27:0 26-28:0 26-29:0 26-30:0 26-31:0 26-32:0 26-33:0 26-34:0 26-35:0 26-36:0 26-37:0 26-38:0 26-39:0 26-40:0 26-41:0
第27个节点: 27-0:0 27-1:0 27-2:0 27-3:0 27-4:0 27-5:0 27-6:0 27-7:0 27-8:0 27-9:0 27-10:0 27-11:0 27-12:0 27-13:0 27-14:0 27-15:0 27-16:0 27-17:0 27-18:0 27-19:0 27-20:0 27-21:0 27-22:0 27-23:0 27-24:0 27-25:0 27-26:0 27-27:0 27-28:0 27-29:0 27-30:0 27-31:0 27-32:0 27-33:0 27-34:0 27-35:0 27-36:0 27-37:0 27-38:0 27-39:0 27-40:0 27-41:0
第28个节点: 28-0:0 28-1:0 28-2:0 28-3:0 28-4:0 28-5:0 28-6:0 28-7:0 28-8:0 28-9:0 28-10:0 28-11:0 28-12:0 28-13:0 28-14:0 28-15:0 28-16:0 28-17:0 28-18:0 28-19:0 28-20:0 28-21:0 28-22:0 28-23:0 28-24:0 28-25:0 28-26:0 28-27:0 28-28:0 28-29:0 28-30:0 28-31:0 28-32:0 28-33:0 28-34:0 28-35:0 28-36:0 28-37:0 28-38:0 28-39:0 28-40:0 28-41:1
第29个节点: 29-0:0 29-1:0 29-2:0 29-3:0 29-4:0 29-5:0 29-6:0 29-7:0 29-8:0 29-9:0 29-10:0 29-11:0 29-12:0 29-13:0 29-14:0 29-15:0 29-16:0 29-17:0 29-18:0 29-19:0 29-20:0 29-21:0 29-22:0 29-23:0 29-24:0 29-25:0 29-26:0 29-27:0 29-28:0 29-29:0 29-30:0 29-31:0 29-32:0 29-33:0 29-34:0 29-35:0 29-36:0 29-37:0 29-38:0 29-39:0 29-40:0 29-41:1
第30个节点: 30-0:0 30-1:0 30-2:0 30-3:0 30-4:0 30-5:0 30-6:0 30-7:0 30-8:0 30-9:0 30-10:0 30-11:0 30-12:0 30-13:0 30-14:0 30-15:0 30-16:0 30-17:0 30-18:0 30-19:0 30-20:0 30-21:0 30-22:0 30-23:0 30-24:0 30-25:0 30-26:0 30-27:0 30-28:0 30-29:0 30-30:0 30-31:0 30-32:0 30-33:0 30-34:0 30-35:0 30-36:0 30-37:0 30-38:0 30-39:0 30-40:0 30-41:1
第31个节点: 31-0:0 31-1:0 31-2:0 31-3:0 31-4:0 31-5:0 31-6:0 31-7:0 31-8:0 31-9:0 31-10:0 31-11:0 31-12:0 31-13:0 31-14:0 31-15:0 31-16:0 31-17:0 31-18:0 31-19:0 31-20:0 31-21:0 31-22:0 31-23:0 31-24:0 31-25:0 31-26:0 31-27:0 31-28:0 31-29:0 31-30:0 31-31:0 31-32:0 31-33:0 31-34:0 31-35:0 31-36:0 31-37:0 31-38:0 31-39:0 31-40:0 31-41:1
第32个节点: 32-0:0 32-1:0 32-2:0 32-3:0 32-4:0 32-5:0 32-6:0 32-7:0 32-8:0 32-9:0 32-10:0 32-11:0 32-12:0 32-13:0 32-14:0 32-15:0 32-16:0 32-17:0 32-18:0 32-19:0 32-20:0 32-21:0 32-22:0 32-23:0 32-24:0 32-25:0 32-26:0 32-27:0 32-28:0 32-29:0 32-30:0 32-31:0 32-32:0 32-33:0 32-34:0 32-35:0 32-36:0 32-37:0 32-38:0 32-39:0 32-40:0 32-41:1
第33个节点: 33-0:0 33-1:0 33-2:0 33-3:0 33-4:0 33-5:0 33-6:0 33-7:0 33-8:0 33-9:0 33-10:0 33-11:0 33-12:0 33-13:0 33-14:0 33-15:0 33-16:0 33-17:0 33-18:0 33-19:0 33-20:0 33-21:0 33-22:0 33-23:0 33-24:0 33-25:0 33-26:0 33-27:0 33-28:0 33-29:0 33-30:0 33-31:0 33-32:0 33-33:0 33-34:0 33-35:0 33-36:0 33-37:0 33-38:0 33-39:0 33-40:0 33-41:1
第34个节点: 34-0:0 34-1:0 34-2:0 34-3:0 34-4:0 34-5:0 34-6:0 34-7:0 34-8:0 34-9:0 34-10:0 34-11:0 34-12:0 34-13:0 34-14:0 34-15:0 34-16:0 34-17:0 34-18:0 34-19:0 34-20:0 34-21:0 34-22:0 34-23:0 34-24:0 34-25:0 34-26:0 34-27:0 34-28:0 34-29:0 34-30:0 34-31:0 34-32:0 34-33:0 34-34:0 34-35:0 34-36:0 34-37:0 34-38:0 34-39:0 34-40:0 34-41:1
第35个节点: 35-0:0 35-1:0 35-2:0 35-3:0 35-4:0 35-5:0 35-6:0 35-7:0 35-8:0 35-9:0 35-10:0 35-11:0 35-12:0 35-13:0 35-14:0 35-15:0 35-16:0 35-17:0 35-18:0 35-19:0 35-20:0 35-21:0 35-22:0 35-23:0 35-24:0 35-25:0 35-26:0 35-27:0 35-28:0 35-29:0 35-30:0 35-31:0 35-32:0 35-33:0 35-34:0 35-35:0 35-36:0 35-37:0 35-38:0 35-39:0 35-40:0 35-41:1
第36个节点: 36-0:0 36-1:0 36-2:0 36-3:0 36-4:0 36-5:0 36-6:0 36-7:0 36-8:0 36-9:0 36-10:0 36-11:0 36-12:0 36-13:0 36-14:0 36-15:0 36-16:0 36-17:0 36-18:0 36-19:0 36-20:0 36-21:0 36-22:0 36-23:0 36-24:0 36-25:0 36-26:0 36-27:0 36-28:0 36-29:0 36-30:0 36-31:0 36-32:0 36-33:0 36-34:0 36-35:0 36-36:0 36-37:0 36-38:0 36-39:0 36-40:0 36-41:1
第37个节点: 37-0:0 37-1:0 37-2:0 37-3:0 37-4:0 37-5:0 37-6:0 37-7:0 37-8:0 37-9:0 37-10:0 37-11:0 37-12:0 37-13:0 37-14:0 37-15:0 37-16:0 37-17:0 37-18:0 37-19:0 37-20:0 37-21:0 37-22:0 37-23:0 37-24:0 37-25:0 37-26:0 37-27:0 37-28:0 37-29:0 37-30:0 37-31:0 37-32:0 37-33:0 37-34:0 37-35:0 37-36:0 37-37:0 37-38:0 37-39:0 37-40:0 37-41:1
第38个节点: 38-0:0 38-1:0 38-2:0 38-3:0 38-4:0 38-5:0 38-6:0 38-7:0 38-8:0 38-9:0 38-10:0 38-11:0 38-12:0 38-13:0 38-14:0 38-15:0 38-16:0 38-17:0 38-18:0 38-19:0 38-20:0 38-21:0 38-22:0 38-23:0 38-24:0 38-25:0 38-26:0 38-27:0 38-28:0 38-29:0 38-30:0 38-31:0 38-32:0 38-33:0 38-34:0 38-35:0 38-36:0 38-37:0 38-38:0 38-39:0 38-40:0 38-41:1
第39个节点: 39-0:0 39-1:0 39-2:0 39-3:0 39-4:0 39-5:0 39-6:0 39-7:0 39-8:0 39-9:0 39-10:0 39-11:0 39-12:0 39-13:0 39-14:0 39-15:0 39-16:0 39-17:0 39-18:0 39-19:0 39-20:0 39-21:0 39-22:0 39-23:0 39-24:0 39-25:0 39-26:0 39-27:0 39-28:0 39-29:0 39-30:0 39-31:0 39-32:0 39-33:0 39-34:0 39-35:0 39-36:0 39-37:0 39-38:0 39-39:0 39-40:0 39-41:1
第40个节点: 40-0:0 40-1:0 40-2:0 40-3:1 40-4:0 40-5:1 40-6:0 40-7:1 40-8:1 40-9:0 40-10:0 40-11:1 40-12:0 40-13:1 40-14:0 40-15:0 40-16:1 40-17:1 40-18:0 40-19:1 40-20:0 40-21:0 40-22:1 40-23:0 40-24:1 40-25:1 40-26:0 40-27:0 40-28:0 40-29:0 40-30:0 40-31:0 40-32:0 40-33:0 40-34:0 40-35:0 40-36:0 40-37:0 40-38:0 40-39:0 40-40:0 40-41:0
第41个节点: 41-0:0 41-1:0 41-2:0 41-3:0 41-4:0 41-5:0 41-6:0 41-7:0 41-8:0 41-9:0 41-10:0 41-11:0 41-12:0 41-13:0 41-14:0 41-15:0 41-16:0 41-17:0 41-18:0 41-19:0 41-20:0 41-21:0 41-22:0 41-23:0 41-24:0 41-25:0 41-26:0 41-27:0 41-28:0 41-29:0 41-30:0 41-31:0 41-32:0 41-33:0 41-34:0 41-35:0 41-36:0 41-37:0 41-38:0 41-39:0 41-40:0 41-41:0
40-->3-->31-->41
40-->5-->36-->41
40-->7-->38-->41
40-->8-->28-->41
40-->11-->29-->41
40-->13-->35-->41
40-->16-->34-->41
40-->17-->32-->41
40-->19-->33-->41
40-->22-->30-->41
40-->24-->39-->41
40-->25-->37-->41

原文地址:https://www.cnblogs.com/DarrenChan/p/6546038.html