1036 Business TravelTitle Description 
Description 
A businessman in a capital city often goes to the towns to do business, and they do it on their own lines to save time.
Suppose there are N towns, the capital is numbered 1, the merchant departs from the capital, there are road connections between the other towns, and if there are direct links between any two towns, it takes a unit of time to travel between them. The country has a well-developed road network, which can reach any town from the capital, and the road network will not be a ring.
Your task is to help the businessman calculate his shortest travel time.
Enter a description 
Input Description 
the first line in the input file has an integer n,1<=n<=30 000, which is the number of towns. The following lines are N-1, each consisting of two integers a  and b  (1<=a, b<=n; a<>b), Indicates a road connection between Town A and town B. In the N+1 Act an integer m, the following M-line, each line has the number of towns that the merchant needs to pass sequentially. 
Output description 
Output Description 
outputs the shortest time the merchant travels in the output file. 
Sample input 
Sample Input 
5
1 2
1 5
3 5
4 5
4
1
3
2
5
Sample output 
Sample Output 
7
Ideas:
Bare LCA .... , template title. Do not understand the code.
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <vector>5#include <algorithm>6 #defineMAXN 300107 8 using namespacestd;9 Tenvector<int> s[30010]; One intfa[maxn][ -],deep[maxn],n,m; A  - voidGetdeep (intKintd) -     { thedeep[k]=D; -          for(intI=1;(1<<i) <=deep[k];i++) -fa[k][i]=fa[fa[k][i-1]][i-1]; -          for(intI=0; I<s[k].size (); i++) +           { -               if(!Deep[s[k][i]]) +                  { Afa[s[k][i]][0]=K; atGetdeep (s[k][i],d+1); -                  } -           }  -     } -      - intLcaintXinty) in   { -       if(deep[x]<Deep[y]) swap (x, y); to       intt=deep[x]-Deep[y]; +        for(intI=0;i< -; i++) -        if((1<<i) &t) x=Fa[x][i];  the        for(intI= -; i>=0; i--) *          { $                if(fa[x][i]!=Fa[y][i])Panax Notoginseng                    { -x=Fa[x][i]; they=Fa[y][i]; +                    } A          }  the     if(x==y)returnx; +     returnfa[x][0];  -   } $    $ intMain () -   { -scanf"%d",&n); the        for(intI=0; i<n-1; i++) -         {Wuyi             intx, y; thescanf"%d%d",&x,&y); - s[y].push_back (x); Wu s[x].push_back (y); -         } AboutGetdeep (1,1);  $scanf"%d",&m);  -     intanss=0; -     intA=1, B; -      for(intI=0; i<m;i++) A          { +scanf"%d",&b); theanss+=deep[a]+deep[b]-2*Deep[lca (A, b)]; -A=b; $                  } theprintf"%d", ANSS); the     return 0;  the}
C + + Road Advanced--lca