Submission #285377

#TimeUsernameProblemLanguageResultExecution timeMemory
285377ScarletSPipes (BOI13_pipes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define ll long long #define sz(x) (int)(x).size() #define pii pair<int,int> #define f first #define s second using namespace std; const int MAXN=1e5+10; int n,m; vector<pii> edges[MAXN]; int scores[MAXN], cur[MAXN], ans[5*MAXN], count[MAXN]; bool done[MAXN]; set<pii> vals[MAXN]; void dfsTree(int c, int p, int x) { for (pii i : edges[c]) if (i.f!=p) { dfsTree(i.f,c,i.s); cur[c]+=ans[i.s]; } if (c!=1) { ans[x]=scores[c]-cur[c]; cur[c]+=ans[x]; } } void treeCase() { dfsTree(1,0,0); if (scores[1]!=cur[1]) { cout<<"-1\n"; return; } for (int i=0;i<m;++i) cout<<ans[i]*2<<"\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int u,v,x=0; cin>>n>>m; for (int i=1;i<=n;++i) cin>>scores[i]; for (int i=0;i<m;++i) { cin>>u>>v; edges[u].push_back({v,i}); edges[v].push_back({u,i}); } if (m==n-1) { treeCase(); return 0; } if (m>n) { cout<<"-1"; return 0; } stack<int> st; for (int i=1;i<=n;++i) { count[i]=sz(edges[i]); if (count[i]==1) st.push(i); } while (sz(st)) { ++x; v=st.top();st.pop(); done[v]=1; for (int i : edges[v]) if (!done[i]) { u=(*(vals[v].lower_bound({i,0}))).second; ans[u]=scores[v]-cur[v]; cur[v]+=ans[u]; cur[i]+=ans[u]; --count[i]; if (count[i]==1) st.push(i); } } if ((n-x+1)&1) { cout<<-1; return 0; } return 0; }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:69:9: error: reference to 'count' is ambiguous
   69 |         count[i]=sz(edges[i]);
      |         ^~~~~
In file included from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:4107:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits<_Iterator>::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4107 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
pipes.cpp:12:43: note:                 'int count [100010]'
   12 | int scores[MAXN], cur[MAXN], ans[5*MAXN], count[MAXN];
      |                                           ^~~~~
pipes.cpp:70:13: error: reference to 'count' is ambiguous
   70 |         if (count[i]==1)
      |             ^~~~~
In file included from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:4107:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits<_Iterator>::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4107 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
pipes.cpp:12:43: note:                 'int count [100010]'
   12 | int scores[MAXN], cur[MAXN], ans[5*MAXN], count[MAXN];
      |                                           ^~~~~
pipes.cpp:78:29: error: cannot convert 'std::pair<int, int>' to 'int' in initialization
   78 |         for (int i : edges[v])
      |                             ^
pipes.cpp:85:19: error: reference to 'count' is ambiguous
   85 |                 --count[i];
      |                   ^~~~~
In file included from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:4107:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits<_Iterator>::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4107 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
pipes.cpp:12:43: note:                 'int count [100010]'
   12 | int scores[MAXN], cur[MAXN], ans[5*MAXN], count[MAXN];
      |                                           ^~~~~
pipes.cpp:86:21: error: reference to 'count' is ambiguous
   86 |                 if (count[i]==1)
      |                     ^~~~~
In file included from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from pipes.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:4107:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits<_Iterator>::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4107 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
pipes.cpp:12:43: note:                 'int count [100010]'
   12 | int scores[MAXN], cur[MAXN], ans[5*MAXN], count[MAXN];
      |                                           ^~~~~