import java.util.*;
public class EdgeWeightedDigraph {
private final int V;
private int E;
private Set<DirectedEdge>[] adj;
public EdgeWeightedDigraph(int V) {
this.V = V;
this.E = E;
adj = (Set<DirectedEdge>[])new Set[V];
for(int v = 0; v < V; v++) {
adj[v] = new HashSet<DirectedEdge>();
}
}
public int V() {return V;}
public int E() {return E;}
public void addEdge(DirectedEdge e) {
adj[e.from()].add(e);
E++;
}
public Iterable<DirectedEdge> adj(int v) {
return adj[v];
}
public Iterable<DirectedEdge> edges() {
Set<DirectedEdge> set = new HashSet<>();
for(int v = 0; v < V; v++)
for(DirectedEdge e : adj[v])
set.add(e);
return set;
}
}