제출 #254235

#제출 시각아이디문제언어결과실행 시간메모리
254235tatyamTraffic (IOI10_traffic)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; } int LocateCentre(int n, int p[], int s[], int d[]){ const int sum = accumulate(p, p + n); vector<vector<int>> g(n); for(int i = 0; i < n - 1; i++){ const int a = s[i], b = d[i]; g[a].push_back(b); g[b].push_back(a); } vector<int> siz(n, 1), dp(n); auto dfs = [&](int from, int at, const auto& dfs) -> void { for(int i : g[at]) if(i != from){ dfs(at, i, dfs); chmax(dp[at], siz[i]); siz[at] += siz[i]; } chmax(dp[at], sum - siz[at]); }; dfs(-1, 0, dfs); return min_element(dp.begin(), dp.end()) - dp.begin(); }

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

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:7:40: error: no matching function for call to 'accumulate(int*&, int*)'
     const int sum = accumulate(p, p + n);
                                        ^
In file included from /usr/include/c++/7/numeric:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:84,
                 from traffic.cpp:1:
/usr/include/c++/7/bits/stl_numeric.h:120:5: note: candidate: template<class _InputIterator, class _Tp> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp)
     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
     ^~~~~~~~~~
/usr/include/c++/7/bits/stl_numeric.h:120:5: note:   template argument deduction/substitution failed:
traffic.cpp:7:40: note:   candidate expects 3 arguments, 2 provided
     const int sum = accumulate(p, p + n);
                                        ^
In file included from /usr/include/c++/7/numeric:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:84,
                 from traffic.cpp:1:
/usr/include/c++/7/bits/stl_numeric.h:146:5: note: candidate: template<class _InputIterator, class _Tp, class _BinaryOperation> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation)
     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
     ^~~~~~~~~~
/usr/include/c++/7/bits/stl_numeric.h:146:5: note:   template argument deduction/substitution failed:
traffic.cpp:7:40: note:   candidate expects 4 arguments, 2 provided
     const int sum = accumulate(p, p + n);
                                        ^