Submission #424546

#TimeUsernameProblemLanguageResultExecution timeMemory
424546KienTranluvChaengSplit the sequence (APIO14_sequence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int O = 1e4 + 1; int n, f[O][4]; vector <vector <int>> g; void dfs(int u, int par = 0){ f[u] = 1; vector <int> d(n + 1); for (int v : g[u]){ if (v != par){ dfs(v, u); d[f[v]] = 1; } } int i; for (i = 1; i <= n; ++ i) if (!d[i]) break; f[u] = i; } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; g.resize(n + 1); for (int i = 1; i < n; ++ i){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1); int ans = 0; for (int i = 1; i <= n; ++ i) ans += f[i]; cout << ans << "\n"; for (int i = 1; i <= n; ++ i) cout << f[i] << "\n"; }

Compilation message (stderr)

sequence.cpp: In function 'void dfs(int, int)':
sequence.cpp:12:10: error: incompatible types in assignment of 'int' to 'int [4]'
   12 |     f[u] = 1;
      |     ~~~~~^~~
sequence.cpp:17:18: error: invalid conversion from 'int*' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive]
   17 |             d[f[v]] = 1;
      |               ~~~^
      |                  |
      |                  int*
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
sequence.cpp:23:10: error: incompatible types in assignment of 'int' to 'int [4]'
   23 |     f[u] = i;
      |     ~~~~~^~~
sequence.cpp: At global scope:
sequence.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      | ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:37:39: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   37 |     for (int i = 1; i <= n; ++ i) ans += f[i];
      |                                   ~~~~^~~~~~~
      |                                       |
      |                                       int*