54 lines
1.4 KiB
Plaintext
54 lines
1.4 KiB
Plaintext
class Graph {
|
|
ArrayList<ArrayList<Integer>> adj;
|
|
ArrayList<ArrayList<Integer>> coords;
|
|
int V;
|
|
Graph(int v) {
|
|
V = v;
|
|
adj = new ArrayList<ArrayList<Integer>>(V);
|
|
coords = new ArrayList<ArrayList<Integer>>(V);
|
|
for (int i = 0; i < V; i++) {
|
|
adj.add(new ArrayList<Integer>());
|
|
coords.add(new ArrayList<Integer>());
|
|
}
|
|
}
|
|
|
|
void draw_vis(boolean[] vis) {
|
|
strokeWeight(20);
|
|
stroke(255);
|
|
for (int i = 0; i < coords.size(); i++) {
|
|
if (!vis[i]) continue;
|
|
point(coords.get(i).get(0), coords.get(i).get(1));
|
|
text(i+1, coords.get(i).get(0)-4, coords.get(i).get(1)+5);
|
|
}
|
|
}
|
|
|
|
void draw_points(int point_weight) {
|
|
strokeWeight(point_weight);
|
|
stroke(#FF0000);
|
|
for (int i = 0; i < coords.size(); i++) {
|
|
point(coords.get(i).get(0), coords.get(i).get(1));
|
|
text(i+1, coords.get(i).get(0)-3, coords.get(i).get(1)+5);
|
|
}
|
|
}
|
|
|
|
void draw_graph(int graph_weight, int point_weight) {
|
|
stroke(#550000);
|
|
strokeWeight(10);
|
|
for (int i = 0; i < adj.size(); i++) {
|
|
for (int idx = 0; idx < adj.get(i).size(); idx++) {
|
|
int e = adj.get(i).get(idx);
|
|
draw_arrow(coords.get(i).get(0), coords.get(i).get(1), coords.get(e).get(0), coords.get(e).get(1), point_weight, graph_weight);
|
|
}
|
|
}
|
|
}
|
|
|
|
void set_coords(int idx, int x, int y) {
|
|
coords.get(idx).add(x);
|
|
coords.get(idx).add(y);
|
|
}
|
|
|
|
void add_edge(int u, int v) {
|
|
adj.get(u).add(v);
|
|
}
|
|
}
|