Submission #872857

#TimeUsernameProblemLanguageResultExecution timeMemory
872857MinaRagy06Two Currencies (JOI23_currencies)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 100'005; vector<array<int, 2>> adj[N]; vector<ll> v[N]; vector<ll> cur; bool dfs(int i, int par, int dest) { if (i == dest) return 1; for (auto [nxt, idx] : adj[i]) { if (nxt == par) continue; for (auto x : v[idx]) { cur.push_back(x); } if (dfs(nxt, i, dest)) { return 1; } for (auto x : v[idx]) { cur.pop_back(); } } return 0; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 0, U, V; i < n - 1; i++) { cin >> U >> V; adj[U].push_back({V, i + 1}); adj[V].push_back({U, i + 1}); } for (int i = 0; i < m; i++) { ll p, c; cin >> p >> c; v[p].push_back(c); } while (q--) { cur.clear(); int s, t; ll x, y; cin >> s >> t >> x >> y; dfs(s, 0, t); sort(cur.begin(), cur.end()); x -= cur.size(); for (int i = 0; i < cur.size(); i++) { if (y - cur[i] >= 0) { y -= cur[i]; x++; } else { break; } } cout << max((ll)x, -1) << '\n'; } return 0; }

Compilation message (stderr)

currencies.cpp: In function 'bool dfs(int, int, int)':
currencies.cpp:19:13: warning: unused variable 'x' [-Wunused-variable]
   19 |   for (auto x : v[idx]) {
      |             ^
currencies.cpp: In function 'int main()':
currencies.cpp:47:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (int i = 0; i < cur.size(); i++) {
      |                   ~~^~~~~~~~~~~~
currencies.cpp:55:24: error: no matching function for call to 'max(long long int, int)'
   55 |   cout << max((ll)x, -1) << '\n';
      |                        ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from currencies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
currencies.cpp:55:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   55 |   cout << max((ll)x, -1) << '\n';
      |                        ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from currencies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
currencies.cpp:55:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   55 |   cout << max((ll)x, -1) << '\n';
      |                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from currencies.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
currencies.cpp:55:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   55 |   cout << max((ll)x, -1) << '\n';
      |                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from currencies.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
currencies.cpp:55:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   55 |   cout << max((ll)x, -1) << '\n';
      |                        ^