Converting edge ( a -> b ) to 2 different edges i . e . ( a -> b ) converts to ( 1 ) . even_a -> odd_b ( 2 ) . odd_a -> even_b since , graph is undirected , so we push them in reverse order too hence , 4 push_back operations are there .
static void addEdge ( int a , int b , int cost ) { adj [ even ( a ) ] . add ( new Pair ( odd ( b ) , cost ) ) ; adj [ odd ( a ) ] . add ( new Pair ( even ( b ) , cost ) ) ; adj [ odd ( b ) ] . add ( new Pair ( even ( a ) , cost ) ) ; adj [ even ( b ) ] . add ( new Pair ( odd ( a ) , cost ) ) ; }