제출 #594543

#제출 시각아이디문제언어결과실행 시간메모리
594543snasibov05기지국 (IOI20_stations)C++14
컴파일 에러
0 ms0 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; int tm = 0; void dfs(int cur, int pr, vector<int>& tin, vector<int>& tout, vector<int>& d, vector<vector<int>>& ed) { tin[cur] = tm++; d[cur] = d[pr] + 1; for (auto to : ed[cur]) { if (to == pr) continue; dfs(to, cur, tin, tout, d, ed); } tout[cur] = tm++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<vector<int>> ed(n); for (int i = 0; i < n-1; ++i) { ed[u[i]].push_back(v[i]); ed[v[i]].push_back(u[i]); } vector<int> d(n), tin(n), tout(n); tm = 0, d[0] = -1; dfs(0, 0, tin, tout, d, ed); vector<int> label(n); for (int i = 0; i < n; ++i){ if (d[i] % 2 == 0) label[i] = tin[i]; else label[i] = tout[i]; } return label; } int find_next_station(int s, int t, vector<int> c) { sort(c.begin(), c.end()); if (s < c[0]){ int prev = s; for (int i = 0; i < c.size() - 1; ++i){ if (prev <= t && t <= c[i]) return c[i]; prev = c[i]; } return c.back(); } else{ int prev = s; for (int i = c.size() - 1; i > 0; --i){ if (c[i] <= t && t <= prev) return c[i]; prev = c[i]; } return c[0]; } }

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

stations.cpp: In function 'void dfs(int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<std::vector<int> >&)':
stations.cpp:10:16: error: reference to 'tm' is ambiguous
   10 |     tin[cur] = tm++;
      |                ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/c++/10/ctime:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:49,
                 from stations.cpp:2:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
stations.cpp:6:5: note:                 'int tm'
    6 | int tm = 0;
      |     ^~
stations.cpp:16:17: error: reference to 'tm' is ambiguous
   16 |     tout[cur] = tm++;
      |                 ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/c++/10/ctime:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:49,
                 from stations.cpp:2:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
stations.cpp:6:5: note:                 'int tm'
    6 | int tm = 0;
      |     ^~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:29:5: error: reference to 'tm' is ambiguous
   29 |     tm = 0, d[0] = -1;
      |     ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/c++/10/ctime:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:49,
                 from stations.cpp:2:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
stations.cpp:6:5: note:                 'int tm'
    6 | int tm = 0;
      |     ^~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i = 0; i < c.size() - 1; ++i){
      |                         ~~^~~~~~~~~~~~~~