import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Random; public class DogboneGenerator { int numEdges; int numColors; int branches; int numSeeds; public DogboneGenerator(int numEdges, int numColors, int branches, int numSeeds) { this.numEdges = numEdges; this.numColors = numColors; this.branches = branches; this.numSeeds = numSeeds; } /** * Run generator with arguments: * * numberOfVertices * * This produces a "dogbone" rainbow tree. For N vertices, this * looks like * * 1 (N-1) * \ / * 3-4-5-....-(N-2) * / \ * 2 N * * The generated tree is rainbow, but you cna easily edit the colors * the colors of the edges 1-2, 2-3, (N-2)-(N-1), and (N-1)-N to introduce * bad nodes that affect the remainder of the tree */ public static void main(String[] args) { int numVertices = Integer.parseInt(args[0]); int numEdges = numVertices; int numColors = numVertices; int numSeeds = 0; int branches = 2; new DogboneGenerator(numEdges, numColors, branches, numSeeds).run(); } Random rand = new Random(); private void run() { generateTree (numEdges); } private void generateTree(int N) { System.out.println("" + numEdges); System.out.println("1 3 1"); System.out.println("2 3 2"); System.out.println((N-2) + " " + (N-1) + " 1"); System.out.println((N-2) + " " + (N) + " 2"); for (int i = 3; i < N-2; ++i) { System.out.println (i + " " + (i+1) + " " + i); } } }