CSES - Datatähti 2023 alku - Results
Submission details
Task:Sadonkorjuu
Sender:Niilo
Submission time:2022-12-02 19:47:40 +0200
Language:C++17
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void lenght()':
input/code.cpp:13:35: error: reference to 'size' is ambiguous
   13 |         vector<pair<int,int>> web[size + 1];
      |                                   ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(con...

Code

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

using namespace std;

int size;
bool *types;

void lenght() {
	// starting vector
	vector<pair<int,int>> web[size + 1];
	int a, b, c;
	for (int i=0; i < size - 1; i++) {
		cin >> a >> b >> c;
		web[a].push_back({c, b});
		web[b].push_back({c, a});
	}
	int sum = 0;
	// array looped
	priority_queue<pair<int,pair<int,int>>> q;
	pair<int,pair<int,int>> p;
	int best;
	for (int i=1; i <= size; i++) {
		if (!types[i]) continue;
		// individual vector
		best = -1e9;
		q.push({0, {i, 0}});
		while (!q.empty()) {
			p = q.top();
			q.pop();
			// best route found -> clearing queue
			if (p.first < best) {
				while (!q.empty()) q.pop();
				break;
			};
			for (auto b : web[p.second.first]) {
				// port
				if (!types[b.second]) best = max(best, p.first - b.first);
				// field
				else if (b.second != p.second.second) {
					q.push({p.first - b.first, {b.second, p.second.first}});
				};
			}
		}
		sum -= best;
	}
	cout << sum << "\n";
}

int main() {
	cin >> size;
	types = new bool[size + 1];
	for (int i=1; i <= size; i++) {
		cin >> types[i];
	}
	lenght();
}