Submission #518596

#TimeUsernameProblemLanguageResultExecution timeMemory
518596blueTraffic (IOI10_traffic)C++17
Compilation error
0 ms0 KiB
//#include "traffic.h" #include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; set<int>* neighbors; struct compare { bool operator () (int c1, int c2) { if(neighbors[c1].size() == neighbors[c2].size()) return c1 < c2; else return neighbors[c1].size() < neighbors[c2].size(); } }; int LocateCenter(int N, int* P, int* A, int* B) { int Q = 0; //total population for(int i = 0; i < N; i++) Q += P[i]; vector<int> S[N]; // list of stress set<int> ne[N]; neighbors = &(ne[0]); //set of neighbors for(int i = 0; i < N-1; i++) { neighbors[A[i]].insert(B[i]); neighbors[B[i]].insert(A[i]); } set<int, compare> C; //set of cities for(int i = 0; i < N; i++) C.insert(i); int res = 2000000001; //final result int k = 0, p, r; // smallest set element, total stress, temporary result int t; //temp int city; while(C.size() > 1) { k = *C.begin(); C.erase(k); p = r = 0; for(int i = 0; i < S[k].size(); i++) { p += S[k][i]; r = max(r, S[k][i]); } if(max(r, Q - P[k] - p) <= res) { city = k; res = max(r, Q - P[k] - p); } t = *(neighbors[k].begin()); C.erase(t); neighbors[t].erase(k); C.insert(t); S[*neighbors[k].begin()].push_back(p + P[k]); } p = r = 0; k = *C.begin(); for(int i = 0; i < S[k].size(); i++) { r = max(r, S[k][i]); p += S[k][i]; } r = max(r, Q - P[k] - p); if(r < res) { res = r; city = k; } return city; } // int main() // { // int N; // cin >> N; // // int *P = new int[N], *A = new int[N-1], *B = new int[N-1]; // for(int i = 0; i < N; i++) cin >> P[i]; // for(int i = 0; i < N-1; i++) cin >> A[i] >> B[i]; // // cout << LocateCenter(N, P, A, B) << '\n'; // return 0; // }

Compilation message (stderr)

traffic.cpp: In function 'int LocateCenter(int, int*, int*, int*)':
traffic.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int i = 0; i < S[k].size(); i++)
      |                        ~~^~~~~~~~~~~~~
traffic.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < S[k].size(); i++)
      |                    ~~^~~~~~~~~~~~~
In file included from /usr/include/c++/10/set:60,
                 from traffic.cpp:4:
/usr/include/c++/10/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = compare; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<int>*]':
/usr/include/c++/10/bits/stl_tree.h:2101:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = compare; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = int]'
/usr/include/c++/10/bits/stl_tree.h:2154:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const int&; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = compare; _Alloc = std::allocator<int>]'
/usr/include/c++/10/bits/stl_set.h:512:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = compare; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, compare, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = int]'
traffic.cpp:33:42:   required from here
/usr/include/c++/10/bits/stl_tree.h:780:8: error: static assertion failed: comparison object must be invocable as const
  780 |        is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~