Submission #1141903

#TimeUsernameProblemLanguageResultExecution timeMemory
1141903AtabayRajabliRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include "race.h" #include <bits/stdc++.h> #define all(v) v.begin(), v.end() using namespace std; const int sz = 2e5 + 5, inf = 1e9 + 7; int n, m, k, ans, w[sz], len[sz], d[sz], used[sz], par[sz]; vector<array<int, 2>> g[sz]; vector<int> cur, tot; void dfs(int v, int p) { w[v] = 1; for(int i : g[v]) { if(i == p) continue; dfs(i, v); w[v] += w[i]; } } int fnd(int v, int p = 0) { for(int i : g[v]) { if(i == p || used[i]) continue; if(w[i] > w[v] / 2) { w[v] -= w[i]; w[i] += w[v]; return fnd(i, v); } } return v; } void dist(int v, int p, int cst) { len[v] = len[p] + 1; d[v] = d[p] + cst; cur.push_back(v); for(auto i : g[v]) { if(i[0] == p || used[i[0]]) continue; dist(i[0], v, x[1]); } } void build(int v) { int c = fnd(v); used[c] = 1; mp[0] = 0; for(auto x : g[c]) { int i = x[0]; if(used[i]) continue; cur.clear(); dist(i, v); for(int j : cur) { if(mp.find(k - d[j]) == mp.end()) continue; ans = min(ans, mp[k - d[j]] + len[j]); } for(int j : cur) { mp[d[j]] = min(mp[d[j]], len[j]); } } mp.clear(); for(auto x : g[c]) { if(used[x[0]]) continue; build(x[1]); } } int best_path(int N, int K, int H[][2], int L[]) { n = N, k = K; for(int i = 0; i < n - 1; i++) { int u = h[i][0], v = h[i][1]; cin >> u >> v; g[u].push_back({v, l[i]}); g[v].push_back({u, l[i]}); } dfs(1, 1); build(1); cout << ans; }

Compilation message (stderr)

race.cpp: In function 'void dfs(int, int)':
race.cpp:14:20: error: cannot convert 'std::array<int, 2>' to 'int' in initialization
   14 |     for(int i : g[v])
      |                    ^
race.cpp: In function 'int fnd(int, int)':
race.cpp:24:20: error: cannot convert 'std::array<int, 2>' to 'int' in initialization
   24 |     for(int i : g[v])
      |                    ^
race.cpp: In function 'void dist(int, int, int)':
race.cpp:45:23: error: 'x' was not declared in this scope
   45 |         dist(i[0], v, x[1]);
      |                       ^
race.cpp: In function 'void build(int)':
race.cpp:53:5: error: 'mp' was not declared in this scope; did you mean 'm'?
   53 |     mp[0] = 0;
      |     ^~
      |     m
race.cpp:59:13: error: too few arguments to function 'void dist(int, int, int)'
   59 |         dist(i, v);
      |         ~~~~^~~~~~
race.cpp:37:6: note: declared here
   37 | void dist(int v, int p, int cst)
      |      ^~~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:83:17: error: 'h' was not declared in this scope
   83 |         int u = h[i][0], v = h[i][1];
      |                 ^
race.cpp:84:21: error: 'v' was not declared in this scope
   84 |         cin >> u >> v;
      |                     ^
race.cpp:85:28: error: 'l' was not declared in this scope
   85 |         g[u].push_back({v, l[i]});
      |                            ^
race.cpp:85:23: error: no matching function for call to 'std::vector<std::array<int, 2> >::push_back(<brace-enclosed initializer list>)'
   85 |         g[u].push_back({v, l[i]});
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 2>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::array<int, 2>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 2>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::array<int, 2> >::value_type&&' {aka 'std::array<int, 2>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp:91:1: warning: no return statement in function returning non-void [-Wreturn-type]
   91 | }
      | ^