Driver code
public static void main ( String [ ] args ) { int n = 10 ; Vector < Integer > [ ] g = new Vector [ n + 1 ] ; for ( int i = 0 ; i < g . length ; i ++ ) g [ i ] = new Vector < Integer > ( ) ; g [ 1 ] . add ( 2 ) ; g [ 2 ] . add ( 1 ) ; g [ 1 ] . add ( 3 ) ; g [ 3 ] . add ( 1 ) ; g [ 1 ] . add ( 4 ) ; g [ 4 ] . add ( 1 ) ; g [ 2 ] . add ( 5 ) ; g [ 5 ] . add ( 2 ) ; g [ 2 ] . add ( 6 ) ; g [ 6 ] . add ( 2 ) ; g [ 3 ] . add ( 7 ) ; g [ 7 ] . add ( 3 ) ; g [ 4 ] . add ( 10 ) ; g [ 10 ] . add ( 4 ) ; g [ 8 ] . add ( 7 ) ; g [ 7 ] . add ( 8 ) ; g [ 9 ] . add ( 7 ) ; g [ 7 ] . add ( 9 ) ; Vector < Integer > v = new Vector < > ( ) ; v . add ( 7 ) ; v . add ( 3 ) ; v . add ( 8 ) ; System . out . print ( findLCA ( n , g , v ) + "NEW_LINE"); } }