Submission #429886

#TimeUsernameProblemLanguageResultExecution timeMemory
429886dreezyStations (IOI20_stations)C++17
Compilation error
0 ms0 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back vector<int> labels; vector<vector<int>> graph; void dfs(int n,int p, int curlabel){ labels[n] = curlabel; for(int adj : graph[n]) { if(adj != p) dfs(adj, n, curlabel + 1); } } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> cnt(n); labels.assign(n, 0); graph.assign( n, vector<int>()); for (int i = 0; i < n - 1; i++) { //cout << u[i]<<", "<<v[i]<<endl; cnt[u[i]]++; cnt[v[i]]++; graph[u[i]].pb(v[i]); graph[v[i]].pb(u[i]); } int root = 0; for(int i=0; i<n; i++) if(cnt[i] >2){ root = i; break; } graph[root] = 0; int counter = 0; for(int branch : graph[root]){ dfs(branch, root,counter * 1000 +1); counter++; } return labels; } int find_next_station(int s, int t, vector<int> c) { int startbranch = s/1000; int endbranch = t/1000; if(s == 0){ return endbranch * 1000 + 1; } if(startbranch == endbranch){ if(s < t) return s + 1; } if( (s - 1) % 1000 == 0) return 0; return s -1; } /************/

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:38:16: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and 'int')
   38 |  graph[root] = 0;
      |                ^
In file included from /usr/include/c++/10/vector:72,
                 from stations.h:1,
                 from stations.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from stations.h:1,
                 from stations.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~