제출 #424773

#제출 시각아이디문제언어결과실행 시간메모리
424773zoooma13The Xana coup (BOI21_xanadu)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define MAX_N 100005 vector <int> state; vector <vector <int>> adj; int dp[2][2][MAX_N]; int dfs(int u ,bool st ,bool sp ,int p = -1){ if(adj[u].size() == 1 && p != -1) return (state[u]^sp) == st? st : MAX_N; auto&ret = dp[st][sp][u]; if(~ret) return ret; ret = MAX_N; vector <pair<int ,int>> chld; for(int&v : adj[u]) if(v != p) chld.push_back({dfs(v ,0 ,st ,u) ,dfs(v ,1 ,st ,u)}); sort(chld.begin() ,chld.end() ,[](auto&i ,auto&j){ return i.second-i.first < j.second-j.first; }); int64_t tot = 0; for(int i = 0; i < chld.size(); i++) tot += chld[i].first; int j = 0; if((state[u]^sp) != st) tot += chld[j].second - chld[j].first ,j++; ret = min(1LL*ret ,tot); while(j < chld.size()){ tot += chld[j].second - chld[j].first ,j++; if(j == chld.size()) break; tot += chld[j].second - chld[j].first ,j++; ret = min(1LL*ret ,tot); } return ret + st; } int main() { int n; scanf("%d",&n); adj.resize(n+1); state.resize(n+1); for(int a ,b ,i = 1; i < n; i++){ scanf("%d%d",&a,&b); adj[a].push_back(b); adj[b].push_back(a); } for(int i = 1; i <= n; i++) scanf("%d",&state[i]); memset(dp ,-1 ,sizeof dp); int ans = min(dfs(1 ,0 ,0) ,dfs(1 ,1 ,0)); printf(ans >= MAX_N? "impossible\n" : "%d\n",ans); }

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

xanadu.cpp: In function 'int dfs(int, bool, bool, int)':
xanadu.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 0; i < chld.size(); i++)
      |                    ~~^~~~~~~~~~~~~
xanadu.cpp:29:27: error: no matching function for call to 'min(long long int, int64_t&)'
   29 |     ret = min(1LL*ret ,tot);
      |                           ^
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 xanadu.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:
xanadu.cpp:29:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   29 |     ret = min(1LL*ret ,tot);
      |                           ^
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 xanadu.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:
xanadu.cpp:29:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   29 |     ret = min(1LL*ret ,tot);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from xanadu.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:
xanadu.cpp:29:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   29 |     ret = min(1LL*ret ,tot);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from xanadu.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:
xanadu.cpp:29:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   29 |     ret = min(1LL*ret ,tot);
      |                           ^
xanadu.cpp:30:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while(j < chld.size()){
      |           ~~^~~~~~~~~~~~~
xanadu.cpp:32:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         if(j == chld.size()) break;
      |            ~~^~~~~~~~~~~~~~
xanadu.cpp:34:31: error: no matching function for call to 'min(long long int, int64_t&)'
   34 |         ret = min(1LL*ret ,tot);
      |                               ^
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 xanadu.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:
xanadu.cpp:34:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   34 |         ret = min(1LL*ret ,tot);
      |                               ^
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 xanadu.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:
xanadu.cpp:34:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   34 |         ret = min(1LL*ret ,tot);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from xanadu.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:
xanadu.cpp:34:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |         ret = min(1LL*ret ,tot);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from xanadu.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:
xanadu.cpp:34:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |         ret = min(1LL*ret ,tot);
      |                               ^
xanadu.cpp: In function 'int main()':
xanadu.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
xanadu.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
xanadu.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d",&state[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~