제출 #672001

#제출 시각아이디문제언어결과실행 시간메모리
672001vjudge1경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include "race.h" #include <bits/stdc++.h> const int INF = 1e9; struct Centroid { vector<bool> vis; map<ll, int> paths; vector<int> sz, par; vector<pair<ll, int>> dis; vector<vector<pair<int, int>>> g; Centroid(const vector<vector<pair<int, int>>> &g) : g(g) { sz.resize(g.size()); vis.resize(g.size()); par.resize(g.size()); } int dfsSz(int u, int p) { sz[u] = 1; for (auto v: g[u]) { if (v.first == p || vis[v.first]) continue; sz[u] += dfsSz(v.first, u); } return sz[u]; } int dfsCentroid(int u, int p, int n) { for (auto v: g[u]) { if (v.first == p || vis[v.first]) continue; if (sz[v.first] > n / 2) return dfsCentroid(v.first, u, n); } return u; } void dfs(int u, int p, int cur, ll curDis) { dis.emplace_back(curDis, cur); for (auto v: g[u]) { if (v.first == p || vis[v.first]) continue; dfs(v.first, u, cur + 1, curDis + v.second); } } int build(int u, int p, int &k) { int centroid = dfsCentroid(u, p, dfsSz(u, p)); if (p == -1) p = centroid; par[centroid] = p; vis[centroid] = 1; int ret = INF; for (auto v: g[centroid]) { if (vis[v.first]) continue; dis.clear(); dfs(v.first, centroid, 1, v.second); for (auto i: dis) { if (paths[k - i.first]) ret = min(ret, i.second + paths[k - i.first]); } for (auto i: dis) { if (!paths[i.first]) paths[i.first] = i.second; paths[i.first] = min(paths[i.first], i.second); } } paths.clear(); for (auto v: g[centroid]) { if (vis[v.first]) continue; ret = min(ret, build(v.first, centroid, k)); } return ret; } }; int best_path(int N, int K, int H[][2], int L[]) { vector<pair<int, int>> g(N + 1); for (int i = 0; i < N - 1; i++) { g[H[i][0]].emplace_back(H[i][1], L[i]); g[H[i][1]].emplace_back(H[i][0], L[i]); } Centroid c(g); int sol = c.build(1, -1, k); return (sol == 1e9 ? -1 : sol); }

컴파일 시 표준 에러 (stderr) 메시지

race.cpp:7:5: error: 'vector' does not name a type
    7 |     vector<bool> vis;
      |     ^~~~~~
race.cpp:8:5: error: 'map' does not name a type
    8 |     map<ll, int> paths;
      |     ^~~
race.cpp:9:5: error: 'vector' does not name a type
    9 |     vector<int> sz, par;
      |     ^~~~~~
race.cpp:10:5: error: 'vector' does not name a type
   10 |     vector<pair<ll, int>> dis;
      |     ^~~~~~
race.cpp:11:5: error: 'vector' does not name a type
   11 |     vector<vector<pair<int, int>>> g;
      |     ^~~~~~
race.cpp:13:20: error: 'vector' does not name a type
   13 |     Centroid(const vector<vector<pair<int, int>>> &g) : g(g) {
      |                    ^~~~~~
race.cpp:13:26: error: expected ',' or '...' before '<' token
   13 |     Centroid(const vector<vector<pair<int, int>>> &g) : g(g) {
      |                          ^
race.cpp:44:37: error: 'll' has not been declared
   44 |     void dfs(int u, int p, int cur, ll curDis) {
      |                                     ^~
race.cpp: In constructor 'Centroid::Centroid(int)':
race.cpp:13:57: error: class 'Centroid' does not have any field named 'g'
   13 |     Centroid(const vector<vector<pair<int, int>>> &g) : g(g) {
      |                                                         ^
race.cpp:13:59: error: 'g' was not declared in this scope
   13 |     Centroid(const vector<vector<pair<int, int>>> &g) : g(g) {
      |                                                           ^
race.cpp:14:9: error: 'sz' was not declared in this scope
   14 |         sz.resize(g.size());
      |         ^~
race.cpp:15:9: error: 'vis' was not declared in this scope
   15 |         vis.resize(g.size());
      |         ^~~
race.cpp:16:9: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   16 |         par.resize(g.size());
      |         ^~~
      |         __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
race.cpp: In member function 'int Centroid::dfsSz(int, int)':
race.cpp:20:9: error: 'sz' was not declared in this scope
   20 |         sz[u] = 1;
      |         ^~
race.cpp:22:22: error: 'g' was not declared in this scope
   22 |         for (auto v: g[u]) {
      |                      ^
race.cpp:23:33: error: 'vis' was not declared in this scope
   23 |             if (v.first == p || vis[v.first])
      |                                 ^~~
race.cpp: In member function 'int Centroid::dfsCentroid(int, int, int)':
race.cpp:33:22: error: 'g' was not declared in this scope
   33 |         for (auto v: g[u]) {
      |                      ^
race.cpp:34:33: error: 'vis' was not declared in this scope
   34 |             if (v.first == p || vis[v.first])
      |                                 ^~~
race.cpp:37:17: error: 'sz' was not declared in this scope
   37 |             if (sz[v.first] > n / 2)
      |                 ^~
race.cpp: In member function 'void Centroid::dfs(int, int, int, int)':
race.cpp:45:9: error: 'dis' was not declared in this scope; did you mean 'dfs'?
   45 |         dis.emplace_back(curDis, cur);
      |         ^~~
      |         dfs
race.cpp:47:22: error: 'g' was not declared in this scope
   47 |         for (auto v: g[u]) {
      |                      ^
race.cpp:48:33: error: 'vis' was not declared in this scope
   48 |             if (v.first == p || vis[v.first])
      |                                 ^~~
race.cpp: In member function 'int Centroid::build(int, int, int&)':
race.cpp:61:9: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   61 |         par[centroid] = p;
      |         ^~~
      |         __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
race.cpp:63:9: error: 'vis' was not declared in this scope
   63 |         vis[centroid] = 1;
      |         ^~~
race.cpp:67:22: error: 'g' was not declared in this scope
   67 |         for (auto v: g[centroid]) {
      |                      ^
race.cpp:71:13: error: 'dis' was not declared in this scope; did you mean 'dfs'?
   71 |             dis.clear();
      |             ^~~
      |             dfs
race.cpp:76:21: error: 'paths' was not declared in this scope
   76 |                 if (paths[k - i.first])
      |                     ^~~~~
race.cpp:77:27: error: 'min' was not declared in this scope; did you mean 'std::min'?
   77 |                     ret = min(ret, i.second + paths[k - i.first]);
      |                           ^~~
      |                           std::min
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: 'std::min' declared here
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
race.cpp:81:22: error: 'paths' was not declared in this scope
   81 |                 if (!paths[i.first])
      |                      ^~~~~
race.cpp:84:17: error: 'paths' was not declared in this scope
   84 |                 paths[i.first] = min(paths[i.first], i.second);
      |                 ^~~~~
race.cpp:84:34: error: 'min' was not declared in this scope; did you mean 'std::min'?
   84 |                 paths[i.first] = min(paths[i.first], i.second);
      |                                  ^~~
      |                                  std::min
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: 'std::min' declared here
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
race.cpp:88:9: error: 'paths' was not declared in this scope
   88 |         paths.clear();
      |         ^~~~~
race.cpp:90:22: error: 'g' was not declared in this scope
   90 |         for (auto v: g[centroid]) {
      |                      ^
race.cpp:94:19: error: 'min' was not declared in this scope; did you mean 'std::min'?
   94 |             ret = min(ret, build(v.first, centroid, k));
      |                   ^~~
      |                   std::min
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: 'std::min' declared here
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:103:5: error: 'vector' was not declared in this scope
  103 |     vector<pair<int, int>> g(N + 1);
      |     ^~~~~~
race.cpp:103:5: note: suggested alternatives:
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 race.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included 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 race.cpp:2:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
race.cpp:103:12: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
  103 |     vector<pair<int, int>> g(N + 1);
      |            ^~~~
      |            std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 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 race.cpp:2:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
race.cpp:103:17: error: expected primary-expression before 'int'
  103 |     vector<pair<int, int>> g(N + 1);
      |                 ^~~
race.cpp:105:9: error: 'g' was not declared in this scope
  105 |         g[H[i][0]].emplace_back(H[i][1], L[i]);
      |         ^
race.cpp:109:16: error: 'g' was not declared in this scope
  109 |     Centroid c(g);
      |                ^
race.cpp:111:30: error: 'k' was not declared in this scope
  111 |     int sol = c.build(1, -1, k);
      |                              ^