func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   vector<int> u[100005];   int d[100005];   int a[100005], b[100005], x[100005];   int p[18][100005];   int up[100005], down[100005];   void go(int i, int pr) {     p[0][i] = pr;     d[i] = d[pr] + 1;     for (int j : u[i])       if (j != pr) {         go(j, i);       }   }   void go2(int i, int pr) {     for (int j : u[i])       if (j != pr) {         go2(j, i);         up[i] += up[j];         down[i] += down[j];       }   }   int lca(int a, int b) {     if (d[a] < d[b]) swap(a, b);     for (int i = 17; i >= 0; i--)       if (d[p[i][a]] >= d[b]) a = p[i][a];     if (a == b) return a;     for (int i = 17; i >= 0; i--)       if (p[i][a] != p[i][b]) {         a = p[i][a];         b = p[i][b];       }     return p[0][a];   }   long long cof[1000005];   long long pw[1000005];   int main() {     scanf( %d , &n);     pw[0] = 1;     for (int i = (1); i < (1000005); i++) {       pw[i] = (pw[i - 1] * 2) % 1000000007ll;       cof[i] = cof[i - 1] + pw[i - 1];       if (cof[i] >= 1000000007ll) cof[i] -= 1000000007ll;     }     for (int i = (0); i < (n - 1); i++) {       int l, m, y;       scanf( %d%d%d , &l, &m, &y);       u[l].push_back(m);       u[m].push_back(l);       a[i] = l;       b[i] = m;       x[i] = y;     }     go(1, 0);     for (int i = (1); i < (18); i++)       for (int j = (1); j < (n + 1); j++) p[i][j] = p[i - 1][p[i - 1][j]];     int pos = 1;     int k;     scanf( %d , &k);     for (int z = (0); z < (k); z++) {       int nxt;       scanf( %d , &nxt);       int l = lca(pos, nxt);       up[pos]++;       up[l]--;       down[nxt]++;       down[l]--;       pos = nxt;     }     go2(1, 0);     long long res = 0;     for (int i = (0); i < (n - 1); i++)       if (x[i]) {         if (d[a[i]] < d[b[i]]) {           int r = up[b[i]];           res += cof[r];         } else {           int r = down[a[i]];           res += cof[r];         }       }     res %= 1000000007ll;     printf( %lld n , res % 1000000007ll);   }   