Пример #1
0
 private static void revDepthFirstSearch(Graph graph, Node actNode) {
   actNode.setExplored(true);
   for (Node node : actNode.getInEdges()) {
     if (!node.isExplored()) {
       revDepthFirstSearch(graph, node);
     }
   }
   actNode.setFinishTime(++t);
   graph.addNodeToNodeMap(actNode);
 }
Пример #2
0
  public static void main(String[] args) throws FileNotFoundException {

    InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("scc/scc.txt");
    in = new Scanner(inputStream);

    Graph graph = new Graph();
    for (int i = 1; i <= initNumberOfVerticies; i++) {
      Node node = new Node(i);
      graph.addNodeToRevMap(node);
    }

    while (in.hasNext()) {
      int first = in.nextInt();
      int second = in.nextInt();
      graph.addEdge(first, second);
    }

    for (int i = initNumberOfVerticies; i > 0; i--) {
      Node actNode = graph.getRevMap().get(i);
      if (!actNode.isExplored()) {
        revDepthFirstSearch(graph, actNode);
      }
    }

    for (int i = initNumberOfVerticies; i > 0; i--) {
      Node actNode = graph.getRevMap().get(i);
      actNode.setExplored(false);
    }

    for (int i = initNumberOfVerticies; i > 0; i--) {
      Node actNode = graph.getNodeMap().get(i);
      if (!actNode.isExplored()) {
        s = actNode;
        numberOfConnections = 0;
        depthFirstSearch(graph, actNode);
        sccSet.add(numberOfConnections);
        // System.out.println("leader" + s.getId());
        // System.out.println("id" + numberOfConnections);
      }
    }

    for (Integer i : sccSet) {
      if (i > 200) {
        System.out.println(i);
      }
    }
  }