Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	int num,x,y;
	vector<int[2]> sides;
	vector<int> nums;
	nums.reserve(num);
	sides.reserve(num - 1);
	cin >> num;

	for (int i = 0; i < num - 1; i++) {
		cin >> x >> y;
		sides.push_back({ x,y });
	}

	for (int i = 0; i < num; i++) {
		cin >> x;
		nums.push_back(x);
	}

	sort(nums.begin(), nums.end(),greater<int>());

	vector<int> outputOrder(num);
	outputOrder.reserve(num);
	int index = 2;
	int sum = nums[1];
	outputOrder[sides[0][0]] = nums[0];
	outputOrder[sides[0][1]] = nums[1];
	for (int i = 1; i < num-1; i++) {
		sum += nums[index];
		if (outputOrder[sides[i][0]])
			outputOrder[sides[i][1]] = nums[index++];
		else
			outputOrder[sides[i][0]] = nums[index++];
	}

	cout << sum << endl;
	for (int i = 0; i < num; i++)
		cout << outputOrder[i] << " ";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:9: error: 'vector' was not declared in this scope
    8 |         vector<int[2]> sides;
      |         ^~~~~~
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:16: error: expected primary-expression before 'int'
    8 |         vector<int[2]> sides;
      |                ^~~
a.cc:9:16: error: expected primary-expression before 'int'
    9 |         vector<int> nums;
      |                ^~~
a.cc:10:9: error: 'nums' was not declared in this scope; did you mean 'num'?
   10 |         nums.reserve(num);
      |         ^~~~
      |         num
a.cc:11:9: error: 'sides' was not declared in this scope
   11 |         sides.reserve(num - 1);
      |         ^~~~~
a.cc:12:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   12 |         cin >> num;
      |         ^~~
      |         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:24:39: error: 'greater' was not declared in this scope; did you mean 'std::greater'?
   24 |         sort(nums.begin(), nums.end(),greater<int>());
      |                                       ^~~~~~~
      |                                       std::greater
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/stl_function.h:353:12: note: 'std::greater' declared here
  353 |     struct greater;
      |            ^~~~~~~
a.cc:24:47: error: expected primary-expression before 'int'
   24 |         sort(nums.begin(), nums.end(),greater<int>());
      |                                               ^~~
a.cc:24:9: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   24 |         sort(nums.begin(), nums.end(),greater<int>());
      |         ^~~~
      |         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:26:16: error: expected primary-expression before 'int'
   26 |         vector<int> outputOrder(num);
      |                ^~~
a.cc:27:9: error: 'outputOrder' was not declared in this scope
   27 |         outputOrder.reserve(num);
      |         ^~~~~~~~~~~
a.cc:40:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   40 |         cout << sum << 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:40:24: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   40 |         cout << sum << endl;
      |                        ^~~~
      |                        std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~