func_code_string: #include <bits/stdc++.h>   template <class T>   class three {     T _first, _second, _third;       public:     T &first, &second, &third;     three(T f, T s, T t) : first(_first), second(_second), third(_third) {       _first = f;       _second = s;       _third = t;     }     three(const three& other) : first(_first), second(_second), third(_third) {       _first = other._first;       _second = other._second;       _third = other._third;     }     const three& operator=(const three& other) {       _first = other._first;       _second = other._second;       _third = other._third;       return *this;     }     bool operator<(const three& other) const {       if (first < other.first)         return true;       else if (first == other.first)         if (second < other.second)           return true;         else if (second == other.second)           if (third < other.third)             return true;           else             return false;         else           return false;       else         return false;     }   };   std::vector<std::vector<int> > edges;   std::vector<std::vector<int> > order;   std::vector<bool> visited;   std::vector<int> number;   int countLeafs(int vertex) {     visited[vertex] = true;     int result = 0;     if (vertex != 1 && edges[vertex].size() == 1) result = 1;     for (int i = 0; i < edges[vertex].size(); ++i)       if (!visited[edges[vertex][i]]) result += countLeafs(edges[vertex][i]);     return result;   }   void printOrder(int vertex) {     std::cout << vertex <<    ;     for (int i = 0; i < order[vertex].size(); ++i) {       printOrder(order[vertex][i]);       std::cout << vertex <<    ;     }   }   bool calcOrder(int vertex, three<int>& range) {     std::set<three<int> > childRanges;     visited[vertex] = true;     for (int i = 0; i < edges[vertex].size(); ++i)       if (!visited[edges[vertex][i]]) {         three<int> result(0, 0, 0);         if (!calcOrder(edges[vertex][i], result)) return false;         childRanges.insert(result);       }     bool bad_tree = false;     for (std::set<three<int> >::iterator i = childRanges.begin();          i != childRanges.end(); ++i) {       std::set<three<int> >::iterator j = i;       ++j;       if (false && vertex == 4 && j != childRanges.end()) {         std::cout <<  i = [  << i->third <<   :   << i->first <<     << i->second                   <<  ]  << std::endl;         std::cout <<  j = [  << j->third <<   :   << j->first <<     << j->second                   <<  ]  << std::endl;       }       if (j != childRanges.end() && (*i).second + 1 != (*j).first)         bad_tree = true;       order[vertex].push_back((*i).third);     }     if (bad_tree) return false;     if (childRanges.size() > 0) {       range.first = childRanges.begin()->first;       range.second = childRanges.rbegin()->second;       range.third = vertex;     } else {       range.first = number[vertex];       range.second = number[vertex];       range.third = vertex;     }     return true;   }   void output2d(const std::string& name,                 const std::vector<std::vector<int> >& array) {     for (int i = 0; i < array.size(); ++i) {       std::cout << name <<  [  << i <<  ] = [ ;       for (int j = 0; j + 1 < array[i].size(); ++j)         std::cout << array[i][j] <<    ;       if (array[i].size() > 0) std::cout << array[i][array[i].size() - 1];       std::cout <<  ]  << std::endl;     }   }   int main() {     int n;     std::cin >> n;     edges.resize(n + 1);     for (int i = 0; i < n - 1; ++i) {       int a, b;       std::cin >> a >> b;       edges[a].push_back(b);       edges[b].push_back(a);     }     visited.resize(n + 1);     std::fill(visited.begin(), visited.end(), false);     int leafCount = countLeafs(1);     number.resize(n + 1);     for (int i = 0; i < leafCount; ++i) {       int vertex;       std::cin >> vertex;       number[vertex] = i + 1;     }     std::fill(visited.begin(), visited.end(), false);     order.resize(n + 1);     three<int> spam(0, 0, 0);     if (calcOrder(1, spam)) {       printOrder(1);     } else       std::cout << -1;     return 0;   }   