use of edu.princeton.cs.algs4.In in project AlgorithmsSolutions by Allenskoo856.
the class KosarajuSCC method main.
public static void main(String[] args) {
Digraph G = new Digraph(new In(args[0]));
KosarajuSCC cc = new KosarajuSCC(G);
int M = cc.count();
StdOut.println(M + " components");
Bag<Integer>[] components = (Bag<Integer>[]) new Bag[M];
for (int i = 0; i < M; i++) {
components[i] = new Bag<Integer>();
}
for (int v = 0; v < G.V(); v++) {
components[cc.id(v)].add(v);
}
for (int i = 0; i < M; i++) {
for (int v : components[i]) {
StdOut.print(v + " ");
}
StdOut.println();
}
}
use of edu.princeton.cs.algs4.In in project AlgorithmsSolutions by Allenskoo856.
the class Ex15 method readInts.
public static int[] readInts(String name) {
In in = new In(name);
String input = in.readAll();
String[] words = input.split("\\s+");
int[] ints = new int[words.length];
for (int i = 0; i < words.length; i++) {
ints[i] = Integer.parseInt(words[i]);
}
return ints;
}
use of edu.princeton.cs.algs4.In in project AlgorithmsSolutions by Allenskoo856.
the class FordFulkerson method main.
public static void main(String[] args) {
FlowNetwork G = new FlowNetwork(new In(args[0]));
int s = 0, t = G.V() - 1;
FordFulkerson maxflow = new FordFulkerson(G, s, t);
StdOut.println("Max flow from " + s + " to " + t);
for (int v = 0; v < G.V(); v++) {
for (FlowEdge e : G.adj(v)) {
if ((v == e.from()) && e.flow() > 0) {
StdOut.println(" " + e);
}
}
}
StdOut.println("Max flow value = " + maxflow.value());
}
use of edu.princeton.cs.algs4.In in project AlgorithmsSolutions by Allenskoo856.
the class DirectedDFS method main.
public static void main(String[] args) {
Digraph G = new Digraph(new In(args[0]));
Bag<Integer> sources = new Bag<Integer>();
for (int i = 1; i < args.length; i++) {
sources.add(Integer.parseInt(args[i]));
}
DirectedDFS reachable = new DirectedDFS(G, sources);
for (int v = 0; v < G.V(); v++) {
if (reachable.marked(v)) {
StdOut.print(v + " ");
}
}
StdOut.println();
}
use of edu.princeton.cs.algs4.In in project AlgorithmsSolutions by Allenskoo856.
the class KruskalMST method main.
public static void main(String[] args) {
In in = new In(args[0]);
EdgeWeightedGraph G = new EdgeWeightedGraph(in);
KruskalMST mst = new KruskalMST(G);
for (Edge e : mst.edges()) {
StdOut.println(e);
}
StdOut.println(mst.weight());
}
Aggregations