Language: C++

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int N;
vector<int> graph[10010];
vector<int> C,ans;
int index = 0;
void dfs(int from, int now){
    //cout << from << " " << now << " " << index << endl;
    ans[now] = C[index];
    for(auto next: graph[now]){
        if(next == from)continue;
        index++;
        dfs(now, next);
    }
}
main(){
    cin >> N;
    vector<int> A(N-1), B(N-1);
    rep(i,0,N-1){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
        graph[A[i]].push_back(B[i]);
        graph[B[i]].push_back(A[i]);
    }
    C.resize(N);
    ans.resize(N);
    rep(i,0,N)cin >> C[i];
    sort(C.rbegin(), C.rend());
    
    dfs(-1, 0);

    ll sum = 0;
    rep(i,0,N-1){
        sum += min(ans[A[i]], ans[B[i]]);
    }
    cout << sum << endl;
    rep(i,0,N){
        cout << ans[i] << " \n"[i==N-1];
    }

}

Compiler output:
a.cc:11:5: error: 'int index' redeclared as different kind of entity
   11 | int index = 0;
      |     ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void dfs(int, int)':
a.cc:14:17: error: no match for 'operator[]' (operand types are 'std::vector<int>' and '<unresolved overloaded function type>')
   14 |     ans[now] = C[index];
      |                 ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:17:14: error: no post-increment operator for type
   17 |         index++;
      |              ^~
a.cc: At global scope:
a.cc:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   21 | main(){
      | ^~~~