Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
int main(){
	int N;
	cin >> N;
	vector<vector<int>> E(N);
	for (int i = 0; i < N - 1; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	vector<int> c(N);
	for (int i = 0; i < N; i++){
		cin >> c[i];
	}
	sort(c.begin(), c.end());
	reverse(c.begin(), c.end());
	vector<int> d(N, 0);
	d[0] = c[0];
	int ans = 0;
	int cnt = 1;
	queue<int> Q;
	Q.push(0);
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (int w : E[v]){
			if (d[w] == 0){
				d[w] = c[cnt];
				ans += d[w];
				cnt++;
				Q.push(w);
			}
		}
	}
	cout << ans << endl;
	for (int i = 0; i < N; i++){
		cout << d[i];
		if (i < N - 1){
			cout << ' ';
		}
	}
	cout << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    7 |         cin >> N;
      |         ^~~
      |         std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:8:9: error: 'vector' was not declared in this scope
    8 |         vector<vector<int>> E(N);
      |         ^~~~~~
a.cc:8:9: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:8:23: error: expected primary-expression before 'int'
    8 |         vector<vector<int>> E(N);
      |                       ^~~
a.cc:14:17: error: 'E' was not declared in this scope
   14 |                 E[a].push_back(b);
      |                 ^
a.cc:17:16: error: expected primary-expression before 'int'
   17 |         vector<int> c(N);
      |                ^~~
a.cc:19:24: error: 'c' was not declared in this scope
   19 |                 cin >> c[i];
      |                        ^
a.cc:21:14: error: 'c' was not declared in this scope
   21 |         sort(c.begin(), c.end());
      |              ^
a.cc:21:9: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   21 |         sort(c.begin(), c.end());
      |         ^~~~
      |         std::sort
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:3:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
a.cc:22:9: error: 'reverse' was not declared in this scope; did you mean 'std::reverse'?
   22 |         reverse(c.begin(), c.end());
      |         ^~~~~~~
      |         std::reverse
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note: 'std::reverse' declared here
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
a.cc:23:16: error: expected primary-expression before 'int'
   23 |         vector<int> d(N, 0);
      |                ^~~
a.cc:24:9: error: 'd' was not declared in this scope
   24 |         d[0] = c[0];
      |         ^
a.cc:27:9: error: 'queue' was not declared in this scope; did you mean 'std::queue'?
   27 |         queue<int> Q;
      |         ^~~~~
      |         std::queue
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_queue.h:96:11: note: 'std::queue' declared here
   96 |     class queue
      |           ^~~~~
a.cc:27:15: error: expected primary-expression before 'int'
   27 |         queue<int> Q;
      |               ^~~
a.cc:28:9: error: 'Q' was not declared in this scope
   28 |         Q.push(0);
      |         ^
a.cc:32:30: error: 'E' was not declared in this scope
   32 |                 for (int w : E[v]){
      |                              ^
a.cc:41:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   41 |         cout << ans << endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:41:24: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   41 |         cout << ans << endl;
      |                        ^~~~
      |                        std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~