Submission #1024600

# Submission time Handle Problem Language Result Execution time Memory
1024600 2024-07-16T08:30:14 Z thinknoexit City Mapping (NOI18_citymapping) C++17
Compilation error
0 ms 0 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
int n;
ll dis[N][N];
int A[N], B[N], W[N], tot;
ll d(int i, int j) {
	if (i == j) return 0;
	if (!dis[i][j]) return dis[i][j] = dis[j][i] = get_distance(i, j);
	return dis[i][j];
}
void play(vector<int>& v, int P) {
	int m = v.size();
	if (m == 1) return;
	ll mx = 0;
	int U = 0, V = 0;
	for (auto& x : v) {
		if (d(P, x) > mx) {
			mx = d(P, x);
			U = x;
		}
	}
	mx = 0;
	for (auto& x : v) {
		if (d(U, x) > mx) {
			mx = d(U, x);
			V = x;
		}
	}
	// U, V is leaf
	ll all = d(U, V);
	vector<pair<ll, int>> in, rem;
	for (auto& x; v) {
		if (d(U, x) + d(x, V) == all) in.push_back({ d(U, x), x });
		else {
			ll extra = (d(U, x) + d(x, V) - all) / 2;
			rem.push_back({ d(U, x) - extra, x });
		}
	}
	sort(in.begin(), in.end());
	sort(rem.begin(), rem.end());
	vector<vector<int>> r;
	vector<int> p2;
	int p = 0;
	for (int i = 1;i < (int)in.size();i++) {
		A[tot] = in[i - 1].second;
		B[tot] = in[i].second;
		W[tot] = in[i].first - in[i - 1].first;
		tot++;
		vector<int> nw;
		ll mn = LLONG_MAX;
		int idx = 0;
		while (p < (int)rem.size() && rem[p].first == in[i].first) {
			int vl = rem[p].second;
			ll extra = (d(U, vl) + d(vl, V) - all) / 2;
			if (extra < mn) {
				mn = extra;
				idx = vl;
			}
			nw.push_back(vl);
			p++;
		}
		if (!nw.empty()) {
			A[tot] = idx;
			B[tot] = in[i].second;
			W[tot] = mn;
			tot++;
			for (auto& x : nw) {
				dis[idx][x] = dis[x][idx] = d(U, x) - mn;
			}
			r.push_back(nw);
			p2.push_back(idx);
		}
	}
	for (int i = 0;i < (int)r.size();i++) {
		play(r[i], p2[i]);
	}
}
void find_roads(int NN, int Q, int A[], int B[], int W[]) {
	n = NN;
	vector<int> init(n);
	iota(init.begin(), init.end(), 1);
	play(init, 1);
	for (int i = 0;i < n - 1;i++) {
		A[i] = ::A[i];
		B[i] = ::B[i];
		W[i] = ::W[i];
		//cout << A[i] << ' ' << B[i] << ' ' << W[i] << '\n';
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void play(std::vector<int>&, int)':
citymapping.cpp:35:7: error: declaration of 'auto& x' has no initializer
   35 |  for (auto& x; v) {
      |       ^~~~
citymapping.cpp:35:16: error: could not convert 'v' from 'std::vector<int>' to 'bool'
   35 |  for (auto& x; v) {
      |                ^
      |                |
      |                std::vector<int>
citymapping.cpp:35:17: error: expected ';' before ')' token
   35 |  for (auto& x; v) {
      |                 ^
      |                 ;
citymapping.cpp:36:60: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
   36 |   if (d(U, x) + d(x, V) == all) in.push_back({ d(U, x), x });
      |                                                            ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from citymapping.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
citymapping.cpp:39:40: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(<brace-enclosed initializer list>)'
   39 |    rem.push_back({ d(U, x) - extra, x });
      |                                        ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from citymapping.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~