func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int Mod = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double e = exp(1);   const double PI = acos(-1);   const double ERR = 1e-10;   int head[maxn], cnt, n, tot, mstnum;   int dfn[maxn], father[maxn], rank_[maxn], sz[maxn];   pair<int, int> range[maxn];   long long c[maxn];   bool mark[maxn];   set<int> se;   unordered_map<long long, int> mp;   struct node {     int v, nxt;   } Edge[2 * maxn];   struct edge {     int u, v, id;     long long w;     edge() {}     edge(int _id, int _u, int _v, long long _w) : id(_id), u(_u), v(_v), w(_w) {}   } mst[2 * maxn];   bool operator<(edge a, edge b) { return a.w < b.w; }   vector<edge> ve[maxn];   void init() {     for (int i = 0; i <= n; i++) {       head[i] = -1;       father[i] = i;       rank_[i] = 0;     }     cnt = 0;     tot = 0;     mstnum = 0;   }   void addedge(int u, int v) {     Edge[cnt].v = v;     Edge[cnt].nxt = head[u];     head[u] = cnt++;   }   void dfs(int id, int fa) {     sz[id] = 1;     range[id].first = 0x3f3f3f3f;     range[id].second = -1;     for (int i = head[id]; i != -1; i = Edge[i].nxt) {       int v = Edge[i].v;       if (v == fa) continue;       dfs(v, id);       range[id].first = min(range[id].first, range[v].first);       range[id].second = max(range[id].second, range[v].second);       sz[id] += sz[v];     }     if (sz[id] == 1) {       dfn[id] = ++tot;       range[id].first = range[id].second = tot;     }   }   int find(int id) {     return father[id] == id ? id : father[id] = find(father[id]);   }   void merge(int x, int y) {     x = find(x);     y = find(y);     if (x != y) {       if (rank_[x] > rank_[y])         father[y] = x;       else {         father[x] = y;         if (rank_[x] == rank_[y]) rank_[y]++;       }     }   }   int main() {     int u, v;     scanf( %d , &n);     init();     for (int i = 1; i <= n; i++) {       scanf( %lld , &c[i]);     }     for (int i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       addedge(u, v);       addedge(v, u);     }     dfs(1, -1);     long long ans = 0;     int num = 0;     for (int i = 1; i <= n; i++) {       mst[i] = edge(i, range[i].first - 1, range[i].second, c[i]);     }     sort(mst + 1, mst + 1 + n);     for (int i = 1; i <= n; i++) {       if (mp.find(mst[i].w) == mp.end()) {         mp[mst[i].w] = ++num;       }       ve[mp[mst[i].w]].push_back(mst[i]);     }     for (int i = 1; i <= num; i++) {       for (auto ed : ve[i]) {         int x = find(ed.u);         int y = find(ed.v);         int id = ed.id;         if (x != y) {           se.insert(id);         }       }       for (auto ed : ve[i]) {         int x = find(ed.u);         int y = find(ed.v);         if (x != y) {           ans += ed.w;           merge(x, y);         }       }     }     printf( %lld %d n , ans, (int)se.size());     for (auto x : se) {       printf( %d  , x);     }     return 0;   }   