Submission #703327

#TimeUsernameProblemLanguageResultExecution timeMemory
703327Chal1shkanRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
# include <bits/stdc++.h>
# include "race.h"
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int> 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 2e5 + 25;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;
 
int n, k, ans;
vector <pii> g[maxn];
int sz[maxn];
bool used[maxn];
map <ll, ll> mn;
 
void dfs_calc (int v, int pa)
{
	sz[v] = 1;
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (to == pa || used[to]) continue;
		dfs_calc(to, v);
		sz[v] += sz[to];
	}
}
 
int find_c (int v, int pa, int siz)
{
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (to == pa || used[to]) continue;
		if (sz[to] + sz[to] > siz)
		{
			return find_c(to, v, siz);
		}
	}
	return v;
}
 
void dfs_add (int v, int pa, int d1, int d2)
{
	mn[d1] = min(mn[d1], d2);
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (to == pa || used[to]) continue;
		dfs_add(to, v, d1 + w, d2 + 1);
	}
}
 
void dfs_del (int v, int pa, int d1, int d2)
{
	mn[d1] = inf;
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (to == pa || used[to]) continue;
		dfs_del(to, v, d1 + w, d2 + 1);
	}
}
 
void dfs_ans (int v, int pa, int d1, int d2)
{
	if (d1 > k) return;
	ans = min(ans, d2 + mn[k - d1]);
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (to == pa || used[to]) continue;
		dfs_ans(to, v, d1 + w, d2 + 1);
	}
}
 
void centroid (int v)
{
	dfs_calc(v, v);
	v = find_c(v, v, sz[v]);	
	mn[0] = 0;
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (used[to]) continue;
		dfs_ans(to, v, w, 1);
		dfs_add(to, v, w, 1);
	}
	mn[0] = inf;
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (used[to]) continue;
		dfs_del(to, v, w, 1);
	}
	used[v] = 1;
	for (pii i : g[v])
	{
		int to = i.ff, w = i.ss;
		if (used[to]) continue;
		centroid(to);	
	}
}
 
int best_path(int N, int K, int H[][2], int L[])
{
  n = N, k = K, ans = inf;
  for(int i = 0; i < n - 1; ++i){
    g[H[i][0] + 1].pb({H[i][1] + 1, L[i]});
    g[H[i][1] + 1].pb({H[i][0] + 1, L[i]});
  }
  for (int i = 1; i < n; ++i) mn[i] = inf; 
  centroid(1);
  return (ans == inf ? -1 : ans);
}

Compilation message (stderr)

race.cpp: In function 'void dfs_calc(int, int)':
race.cpp:36:18: warning: unused variable 'w' [-Wunused-variable]
   36 |   int to = i.ff, w = i.ss;
      |                  ^
race.cpp: In function 'int find_c(int, int, int)':
race.cpp:47:18: warning: unused variable 'w' [-Wunused-variable]
   47 |   int to = i.ff, w = i.ss;
      |                  ^
race.cpp: In function 'void dfs_add(int, int, int, int)':
race.cpp:59:25: error: no matching function for call to 'min(std::map<long long int, long long int>::mapped_type&, int&)'
   59 |  mn[d1] = min(mn[d1], d2);
      |                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
race.cpp:59:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   59 |  mn[d1] = min(mn[d1], d2);
      |                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
race.cpp:59:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   59 |  mn[d1] = min(mn[d1], d2);
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
race.cpp:59:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |  mn[d1] = min(mn[d1], d2);
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
race.cpp:59:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |  mn[d1] = min(mn[d1], d2);
      |                         ^
race.cpp: In function 'void dfs_ans(int, int, int, int)':
race.cpp:82:32: error: no matching function for call to 'min(int&, std::map<long long int, long long int>::mapped_type)'
   82 |  ans = min(ans, d2 + mn[k - d1]);
      |                                ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
race.cpp:82:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::map<long long int, long long int>::mapped_type' {aka 'long long int'})
   82 |  ans = min(ans, d2 + mn[k - d1]);
      |                                ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
race.cpp:82:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::map<long long int, long long int>::mapped_type' {aka 'long long int'})
   82 |  ans = min(ans, d2 + mn[k - d1]);
      |                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
race.cpp:82:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   82 |  ans = min(ans, d2 + mn[k - d1]);
      |                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
race.cpp:82:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   82 |  ans = min(ans, d2 + mn[k - d1]);
      |                                ^
race.cpp: In function 'void centroid(int)':
race.cpp:113:18: warning: unused variable 'w' [-Wunused-variable]
  113 |   int to = i.ff, w = i.ss;
      |                  ^