Vector to store tree
@ SuppressWarnings ( " unchecked " ) static List < List < int [ ] > > graph = new ArrayList ( ) ; static void addEdge ( int u , int v , int cost ) { graph . get ( u ) . add ( new int [ ] { v , cost } ) ; graph . get ( v ) . add ( new int [ ] { u , cost } ) ; }