Submission #292435

# Submission time Handle Problem Language Result Execution time Memory
292435 2020-09-07T01:11:37 Z shrek12357 Traffic (IOI10_traffic) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include "traffic.h"
using namespace std;
 
#define MAXN 1000005
vector<int> edges[MAXN];
int best = INT_MAX;
long long totSum = 0;
long long subtree[MAXN];
long long vals[MAXN];
 
void dfs(int src, int par) {
	int val = 0;
	int curSum = vals[src];
	for (auto i : edges[src]) {
		if (i == par) {
			continue;
		}
		dfs(i, src);
		val = max(val, subtree[i]);
		curSum += subtree[i];
	}
	val = max(val, totSum - curSum);
	best = min(best, val);
	subtree[src] = curSum;
}
 
int LocateCentre(int n, int p[MAXN], int s[MAXN], int d[MAXN]) {
	for (int i = 0; i < n; i++) {
		totSum += p[i];
		vals[i] = p[i];
		subtree[i] = 0;
		if (i != n - 1) {
			edges[s[i]].push_back(d[i]);
			edges[d[i]].push_back(s[i]);
		}
	}
	dfs(0, 0);
	return best;
}

Compilation message

traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:29:28: error: no matching function for call to 'max(int&, long long int&)'
   29 |   val = max(val, subtree[i]);
      |                            ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
traffic.cpp:29:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   29 |   val = max(val, subtree[i]);
      |                            ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
traffic.cpp:29:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   29 |   val = max(val, subtree[i]);
      |                            ^
In file included from /usr/include/c++/9/algorithm:62,
                 from traffic.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
traffic.cpp:29:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |   val = max(val, subtree[i]);
      |                            ^
In file included from /usr/include/c++/9/algorithm:62,
                 from traffic.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
traffic.cpp:29:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |   val = max(val, subtree[i]);
      |                            ^
traffic.cpp:32:32: error: no matching function for call to 'max(int&, long long int)'
   32 |  val = max(val, totSum - curSum);
      |                                ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
traffic.cpp:32:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   32 |  val = max(val, totSum - curSum);
      |                                ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from traffic.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
traffic.cpp:32:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   32 |  val = max(val, totSum - curSum);
      |                                ^
In file included from /usr/include/c++/9/algorithm:62,
                 from traffic.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
traffic.cpp:32:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   32 |  val = max(val, totSum - curSum);
      |                                ^
In file included from /usr/include/c++/9/algorithm:62,
                 from traffic.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
traffic.cpp:32:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   32 |  val = max(val, totSum - curSum);
      |                                ^