제출 #302287

#제출 시각아이디문제언어결과실행 시간메모리
302287nhdtxdy경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define eb emplace_back
#define Size(v) (int)v.size()
using namespace std;

// Always
const int nax = 2e5 + 5, INF = 1e9 + 7;
int n, k;
vector<pair<int, int>> adj[nax];
map<int, int> vec[nax];
int dist[nax], ans[nax], sz[nax], dep[nax];

void getsz(int v, int p = 0) {
	sz[v] = 1;
	for (auto &q : adj[v]) {
		int c = q.first, w = q.second;
		if (c == p) continue;
		dep[c] = dep[v] + 1;
		dist[c] = dist[v] + w;
		getsz(c, v);
		sz[v] += sz[c];
	}
}

void dfs(int v, int p = 0, bool keep = false) {
	int maxi = -1, bigchild = -1;
	for (auto &q : adj[v]) {
		int u = q.first;
		if (u == p) continue;
		if (maxi < sz[u]) {
			maxi = sz[u];
			bigchild = u;
		}
	}
	for (auto &q : adj[v]) {
		int u = q.first;
		if (u == p || u == bigchild) continue;
		dfs(u, v, false);
	}
	if (bigchild != -1) {
		dfs(bigchild, v, true);
		swap(vec[v], vec[bigchild]);
	}
	vec[v][dist[v]] = dep[v];	
	int subtract = dist[v];

	if (vec[v].find(k + dist[v]) != vec[v].end()) {
		ans[v] = min(ans[v], vec[v][k + dist[v]] - dep[v]);
	}
	int target = k + 2 * subtract;
	for (auto &q : adj[v]) {
		int c = q.first;
		if (c == p || c == bigchild) continue;
		if (vec[c].find(k + dist[v]) != vec[c].end()) {
			ans[v] = min(ans[v], vec[c][k + dist[v]] - dep[v]);
		}
		for (auto &u : vec[c]) {
			if (vec[v].find(target - u.first) != vec[v].end()) {
				ans[v] = min(ans[v], u.second + vec[v][target - u.first] - 2 * dep[v]);
			}
		}
		for (auto &u : vec[c]) {
			if (vec[v].find(u.first) != vec[v].end()) vec[v][u.first] = min(vec[v][u.first], u.second);
			else vec[v][u.first] = u.second;
		}
	}
}

int32_t best_path(int32_t N, int32_t K, int32_t H[][2], int32_t L[]) {
	fill(ans, ans + nax, INF);
	n = N;
	k = K;
	for (int i = 0; i < n - 1; ++i) {
		int u = H[i][0], v = H[i][1];
		++u, ++v;
		adj[u].eb(v, L[i]);
		adj[v].eb(u, L[i]);
	}
	getsz(1);
	dfs(1);
	int32_t res = INF;
	for (int i = 1; i <= n; ++i) res = min(res, ans[i]);
	return res;
}

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'int32_t best_path(int32_t, int32_t, int32_t (*)[2], int32_t*)':
race.cpp:85:52: error: no matching function for call to 'min(int32_t&, long long int&)'
   85 |  for (int i = 1; i <= n; ++i) res = min(res, ans[i]);
      |                                                    ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
race.cpp:85:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   85 |  for (int i = 1; i <= n; ++i) res = min(res, ans[i]);
      |                                                    ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
race.cpp:85:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   85 |  for (int i = 1; i <= n; ++i) res = min(res, ans[i]);
      |                                                    ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
race.cpp:85:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   85 |  for (int i = 1; i <= n; ++i) res = min(res, ans[i]);
      |                                                    ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
race.cpp:85:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   85 |  for (int i = 1; i <= n; ++i) res = min(res, ans[i]);
      |                                                    ^