제출 #456196

#제출 시각아이디문제언어결과실행 시간메모리
456196sean617경주 (Race) (IOI11_race)C++98
컴파일 에러
0 ms0 KiB
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <queue> #define N 200005 #define A 1000005 using namespace std; int n, k, mn, M = 1e9, s[A], sz[N]; bool v2[N]; vector<int> a[N], b[N]; queue<int> qu; int gs(int p, int q) { int i, t; sz[p] = 1; for (i = 0; i < a[p].size(); i++) { t = a[p][i]; if (t == q || v2[t]) continue; sz[p] += gs(t, p); } return sz[p]; } int gc(int p, int q, int nn) { int i, t; for (i = 0; i < a[p].size(); i++) { t = a[p][i]; if (t != q && !v2[t] && sz[t] *2 > nn) return gc(t, p, nn); } return p; } void g(int p, int q, int w, int cnt) { int i, t; if (w > k) return; mn = min(mn, cnt + s[k - w]); for (i = 0; i < a[p].size(); i++) { t = a[p][i]; if (t == q || v2[t]) continue; g(t, p, w + b[p][i], cnt + 1); } // if (s[w] > cnt) { // s[w] = cnt; // qu.push(w); // } } void up(int p, int q, int w, int cnt) { int i, t; if (w > k) return; if (s[w] > cnt) { s[w] = cnt; qu.push(w); } for (i = 0; i < a[p].size(); i++) { t = a[p][i]; if (t == q || v2[t]) continue; up(t, p, w + b[p][i], cnt + 1); } } void f(int p) { int i, t, cen; gs(p, -1); cen = gc(p, -1, sz[p]); v2[cen] = 1; while (!qu.empty()) { t = qu.front(); qu.pop(); s[t] = M; } s[0] = 0; for (i = 0; i < a[cen].size(); i++) { t = a[cen][i]; if (v2[t]) continue; g(t, -1, b[cen][i], 1); up(t, -1, b[cen][i], 1); } for (i = 0; i < a[cen].size(); i++) { t = a[cen][i]; if (v2[t]) continue; f(t); } } int main() { int i, t1, t2, t3; cin >> n >> k; for (i = 0; i < n - 1; i++) { scanf ("%d %d %d", &t1, &t2, &t3); a[t1].push_back(t2); b[t1].push_back(t3); a[t2].push_back(t1); b[t2].push_back(t3); } mn = M; for (i = 0; i <= k; i++) s[i] = M; f(0); if (mn == M) mn = -1; cout << mn; return 0; }

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

race.cpp: In function 'int gs(int, int)':
race.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (i = 0; i < a[p].size(); i++) {
      |              ~~^~~~~~~~~~~~~
race.cpp: In function 'int gc(int, int, int)':
race.cpp:28:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (i = 0; i < a[p].size(); i++) {
      |              ~~^~~~~~~~~~~~~
race.cpp: In function 'void g(int, int, int, int)':
race.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for (i = 0; i < a[p].size(); i++) {
      |              ~~^~~~~~~~~~~~~
race.cpp: In function 'void up(int, int, int, int)':
race.cpp:57:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for (i = 0; i < a[p].size(); i++) {
      |              ~~^~~~~~~~~~~~~
race.cpp: In function 'void f(int)':
race.cpp:74:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for (i = 0; i < a[cen].size(); i++) {
      |              ~~^~~~~~~~~~~~~~~
race.cpp:80:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |  for (i = 0; i < a[cen].size(); i++) {
      |              ~~^~~~~~~~~~~~~~~
race.cpp: In function 'int main()':
race.cpp:92:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   scanf ("%d %d %d", &t1, &t2, &t3);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccDSi909.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccrtXT09.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccrtXT09.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status