LCA
# pragma GCC optimize(2) # include <bits/stdc++.h> using namespace std ; typedef long long ll ; # define pi acos(-1.0) # define e exp(1.0) const ll maxn = 50 ; vector < ll > G [ maxn ] ; ll parent [ maxn ] ; ll depth [ maxn ] ; ll root ; //预处理出来父节点和深度 void DFS ( ll v , ll p , ll d ) //argument:当前节点 父节点 当前节点的深度 { depth [ v ] = d ; parent [ v ] = p ; ll i , u ; for ( i = 0 ; i < G [ v ] . size ( ) ; i ++ ) { u = G [ v ] [ i ] ; if ( u != p ) DFS ( u , v , d + 1 ) ; } return ; } ll LCA ( ll u , ll v ) { if ( u == v ) return u ; //先让u,v上升到同样高度 if ( depth [ u ] < depth [ v ] ) //每次让u向v看齐 swap ( u ,