Submission #896097

#TimeUsernameProblemLanguageResultExecution timeMemory
896097starchanRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)2e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
int n, k;
vector<in> adj[MX];
int sz[MX]; 
vector<int> curr;
vector<bool> cut;
stack<vector<in>> wow;
void dfs1(int u, int p)
{
	sz[u] = 1;
	for(in vw: adj[u])
	{
		int v = vw.f;
		if(cut[v])
			continue;
		if(v == p)
			continue;
		dfs1(v, u);
		sz[u]+=sz[v];
	}
	return;
}
vector<in> comp[MX];
vector<int> centr[MX];
int centroid(int root, int u, int p)
{
	for(in vw: adj[u])
	{
		int v = vw.f;
		if(cut[v])
			continue;
		if(v==p)
			continue;
		if(2*sz[v] > sz[root])
			return centroid(root, v, u);
	}
	return u;
}
void dfs2(int u, int p, int lvl, int d)
{
	curr.pb({d, lvl});
	for(in vw: adj[u])
	{
		int v = vw.f;
		int w = vw.s;
		if(cut[v])
			continue;
		if(v==p)
			continue;
		int cost = d+w;
		if(cost > k)
			cost = k+1;
		dfs2(root, v, u, lvl+1, cost);
	}
	return;
}
int centroid_decomposition(int u)
{
	dfs1(u, -1);
	int root = centroid(u, u, -1);
	cut[root] = 1;
	for(in vw: adj[root])
	{
		int v = vw.f;
		if(cut[v])
			continue;
		curr.clear();
		dfs2(v, -root, 1, vw.s);
		wow.push(curr);
		int w = centroid_decomposition(v);
		comp[w] = wow.top();
		wow.pop();
	}
	return root;
}
int dfs3(int u, int p)
{
	int ans = n+1;
	map<int, int> freq;
	freq[0] = 0;
	for(int v: centr[u])
	{
		ans = min(ans, dfs3(v, u));
		for(in L_edge: comp[v])
		{
			int L = L_edge.f;
			int dep = L_edge.s;
			if(L > k)
				continue;
			if(freq.find(k-L) == freq.end())
				continue;
			ans = min(ans, dep+freq[k-L]);
		}
		for(in L_edge: comp[v])
		{
			int L = L_edge.f;
			int dep = L_edge.s;
			if(freq.find(L) == freq.end())
				freq[L] = dep;
			else
				freq[L] = min(freq[L], dep);
		}
	}
	return ans;
}
int best_path(int N, int K, int h[][2], int L[])
{
	n = N;
	k = K;
	for(int i = 1; i <= n; i++)
	{
		adj[i].clear();
		centr[i].clear();
	}
	for(int i = 0; i < n-1; i++)
	{
		int u = h[i][0];
		int v = h[i][1];
		u++;
		v++;
		int l = L[i];
		adj[u].pb({v, l});
		adj[v].pb({u, l});
	}
	cut.assign(n+1, 0);
	int root = centroid_decomposition(1);
	int ans = dfs3(root, -1);
	if(ans == (n+1))
		ans = -1;
	return ans;
}
/*
signed main()
{
	int V, KK;
	cin >> V >> KK;
	int h[V-1][2];	
	int L[V-1];
	for(int i = 0; i < V-1; i++)
		cin >> h[i][0] >> h[i][1] >> L[i];
	int ok = best_path(V, KK, h, L);
	cout << ok << endl; 
	return 0;
}
*/

Compilation message (stderr)

race.cpp: In function 'void dfs2(int, int, int, int)':
race.cpp:51:18: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   51 |  curr.pb({d, lvl});
      |                  ^
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 race.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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = 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 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 = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = 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<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp:63:8: error: 'root' was not declared in this scope
   63 |   dfs2(root, v, u, lvl+1, cost);
      |        ^~~~
race.cpp: In function 'int centroid_decomposition(int)':
race.cpp:79:16: error: no matching function for call to 'std::stack<std::vector<std::pair<int, int> > >::push(std::vector<int>&)'
   79 |   wow.push(curr);
      |                ^
In file included from /usr/include/c++/10/stack:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:89,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_stack.h:239:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::vector<std::pair<int, int> >; _Sequence = std::deque<std::vector<std::pair<int, int> >, std::allocator<std::vector<std::pair<int, int> > > >; std::stack<_Tp, _Sequence>::value_type = std::vector<std::pair<int, int> >]'
  239 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_stack.h:239:30: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const value_type&' {aka 'const std::vector<std::pair<int, int> >&'}
  239 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_stack.h:244:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(std::stack<_Tp, _Sequence>::value_type&&) [with _Tp = std::vector<std::pair<int, int> >; _Sequence = std::deque<std::vector<std::pair<int, int> >, std::allocator<std::vector<std::pair<int, int> > > >; std::stack<_Tp, _Sequence>::value_type = std::vector<std::pair<int, int> >]'
  244 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_stack.h:244:25: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::stack<std::vector<std::pair<int, int> > >::value_type&&' {aka 'std::vector<std::pair<int, int> >&&'}
  244 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~