import java.util.*;
public class EdgeWeightedGraph {
private final int V;
private int E;
private Set<Edge>[] adj;
public EdgeWeightedGraph(int V) {
this.V = V;
this.E = 0;
adj = (Set<Edge>[]) new HashSet[V];
for(int v = 0; v < V; v++) {
adj[v] = new HashSet<Edge>();
}
}
public int V() {return V;}
public int E() {return E;}
public void addEdge(Edge e) {
int v = e.either(), w = e.other(v);
adj[v].add(e);
adj[w].add(e);
E++;
}
public Iterable<Edge> adj(int v) {return adj[v];}
public Iterable<Edge> edges() {
Set<Edge> b = new HashSet<>();
for(int v = 0; v < V; v++)
for(Edge e : adj[v])
if(e.other(v) > v)
b.add(e);
return b;
}
}