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 .
void addEdge ( int a , int b , int cost ) { adj [ even ( a ) ] . push_back ( { odd ( b ) , cost } ) ; adj [ odd ( a ) ] . push_back ( { even ( b ) , cost } ) ; adj [ odd ( b ) ] . push_back ( { even ( a ) , cost } ) ; adj [ even ( b ) ] . push_back ( { odd ( a ) , cost } ) ; }