Java:
adj = (Bag<Integer>[]) new Bag[V];
for (int v = 0; v < V; v++)
adj[v] = new Bag<Integer>();
C++:
vector<vector<int>> adj;
for(int v=0;v<V;v++) adj.push_back(vector<int>());
Java:
public void addEdge(int v, int w)
{
adj[v].add(w);
adj[w].add(v);
}
C++:
public void addEdge(int v, int w)
{
adj[v].push_back(w);
adj[w].push_back(v);
}
One more thing: BigInteger can store numbers much larger than int. But it's not necessary to use BigInteger. Because w and v in addEdge must be less than V(V is a int) or it will overflow the range of the array.