제출 #1128463

#제출 시각아이디문제언어결과실행 시간메모리
1128463algoproclub기지국 (IOI20_stations)C++20
컴파일 에러
0 ms0 KiB
#include "stations.h" #include <algorithm> #include <vector> using namespace std; vector<vector<int>> g; vector<int> intime, outtime, depth; int time; void dfs(int v) { intime[v] = time++; for (int x : g[v]) if (intime[x] == -1) { depth[x] = depth[v] + 1; dfs(x); } outtime[v] = time++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { g.assign(n, {}); intime.assign(n, -1); outtime.assign(n, -1); depth.assign(n, 0); for (int i = 0; i < n - 1; i++) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } time = 0; dfs(0); vector<int> labels(n); for (int i = 0; i < n; i++) { labels[i] = depth[i] % 2 == 0 ? intime[i] / 2 : outtime[i] / 2; } return labels; } int find_next_station(int s, int t, vector<int> c) { // sort(c.begin(), c.end()); they are already sorted if (s < c[0]) { // s: intime, c[i]: outtime, c.back(): parent of s // subtree of s: s < t <= c[c.size() - 2], // except if s==0 (root), but the below code is correct for it, too if (t < s || c.size() == 1 || t > c[c.size() - 2]) return c.back(); return *lower_bound(c.begin(), c.end(), t); } else { // s: outtime, c[i]: intime, c[0]: parent of s // subtree of s: c[1] <= t < s if (t > s || c.size() == 1 || t < c[1]) return c[0]; return *(upper_bound(c.begin(), c.end(), t) - 1); } }

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

stations.cpp:9:5: error: 'int time' redeclared as different kind of entity
    9 | int time;
      |     ^~~~
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/gthr.h:148,
                 from /usr/include/c++/11/ext/atomicity.h:35,
                 from /usr/include/c++/11/bits/ios_base.h:39,
                 from /usr/include/c++/11/streambuf:41,
                 from /usr/include/c++/11/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/11/iterator:66,
                 from /usr/include/c++/11/bits/ranges_algobase.h:36,
                 from /usr/include/c++/11/bits/ranges_algo.h:35,
                 from /usr/include/c++/11/algorithm:64,
                 from stations.cpp:2:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
stations.cpp: In function 'void dfs(int)':
stations.cpp:12:17: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
   12 |     intime[v] = time++;
      |                 ^~~~
stations.cpp:12:17: error: lvalue required as increment operand
stations.cpp:18:18: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
   18 |     outtime[v] = time++;
      |                  ^~~~
stations.cpp:18:18: error: lvalue required as increment operand
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:30:14: error: assignment of function 'time_t time(time_t*)'
   30 |         time = 0;
      |         ~~~~~^~~