제출 #1353772

#제출 시각아이디문제언어결과실행 시간메모리
1353772ChinguunRace (IOI11_race)C++20
컴파일 에러
0 ms0 KiB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define meta int tm = (tl + tr) / 2, x = i * 2 + 1, y = x + 1

const int N = 2e5 + 7;
const int TN = 4 * N;
const int oo = 1e9;
const int mod = 1e9 + 7;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

int n, k, p[30][N], d[30][N], lvl[N], mn = oo, pw[30];
vii v[N];

void dfs (int o, int par) {
	for (auto c : v[o]) {
		if (c.ff == par) continue;
		lvl[c.ff] = lvl[o] + 1;
		p[0][c.ff] = o;
		d[0][c.ff] = c.ss;
		dfs(c.ff, o);
	}
}

pii distance (int x, int y) {
	if (lvl[x] > lvl[y])
		swap(x, y);

	int d1 = 0, d2 = 0;
	for (int i = 20; i >= 0; i--) {
		if (lvl[y] - lvl[x] >= pw[i]) {
			d1 += d[i][y];
			d2 += pw[i];
			y = p[i][y];
		}
	}
	for (int i = 20; i >= 0; i--) {
		if (p[i][x] != p[i][y]) {
			d1 += d[i][x] + d[i][y];
			d2 += pw[i] + pw[i];
			x = p[i][x];
			y = p[i][y];
		}
	}
	if (x != y) {
		d1 += d[0][x] + d[0][y];
		d2 += 2;
	}
	return {d1, d2};
}

int best_path(int N, int K, int H[][2], int L[]) {
	n = N;
	k = K;
	for (int i = 0; i < n; i++) {
		v[H[i][0]].pb({v[H[i][1]], L[i]});
		v[H[i][1]].pb({v[H[i][0]], L[i]});
	}
	pw[0] = 1;
	for (int i = 1; i <= 20; i++)
		pw[i] = pw[i - 1] * 2;

	dfs(0, 0);
	for (int i = 1; i <= 20; i++) {
		for (int j = 0; j < n; j++) {
			p[i][j] = p[i - 1][p[i - 1][j]];
			d[i][j] = d[i - 1][j] + d[i - 1][p[i - 1][j]];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			pii pr = distance(i, j);
			if (pr.ff == k) {
				if (pr.ss < mn) mn = pr.ss;
			}
		}
	}
	if (mn == oo) return -1;
	return mn;
}

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

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:65:30: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   65 |                 v[H[i][0]].pb({v[H[i][1]], L[i]});
      |                 ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from race.cpp:2:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp:66:30: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   66 |                 v[H[i][1]].pb({v[H[i][0]], L[i]});
      |                 ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~