제출 #604696

#제출 시각아이디문제언어결과실행 시간메모리
604696SamAnd기지국 (IOI20_stations)C++17
76 / 100
956 ms824 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define m_p make_pair #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define fi first #define se second typedef long long ll; const int N = 1003; vector<int> g[N]; int ti; int tin[N], tout[N]; int d[N]; void dfs(int x, int p) { if (x == p) d[x] = 0; else d[x] = d[p] + 1; tin[x] = ti++; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; if (h == p) continue; dfs(h, x); } tout[x] = ti++; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { for (int i = 0; i < n; ++i) g[i].clear(); for (int i = 0; i < n - 1; ++i) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } ti = 0; dfs(0, 0); vector<int> ans; for (int x = 0; x < n; ++x) { if (d[x] % 2 == 0) ans.push_back(tin[x]); else ans.push_back(tout[x]); } /*for (int i = 0; i < sz(ans); ++i) cout << ans[i] << ' '; cout << endl;*/ return ans; } int find_next_station(int x, int y, std::vector<int> v) { for (int i = 0; i < sz(v); ++i) { if (v[i] == y) return y; } if (x == 0) { sort(all(v)); for (int i = 0; i < sz(v) - 1; ++i) { if (v[i] < y && y < v[i + 1]) return v[i + 1]; } return v[0]; } if (x > v[0]) { sort(all(v)); for (int i = 1; i < sz(v) - 1; ++i) { if (v[i] < y && y < v[i + 1]) return v[i]; } if (v.back() < y && y < x) return v.back(); return v[0]; } else { sort(all(v)); for (int i = 0; i < sz(v) - 2; ++i) { if (v[i] < y && y < v[i + 1]) return v[i + 1]; } if (x < y && y < v[0]) return v[0]; return v.back(); } } /* 1 5 2000 0 1 0 2 2 3 2 4 1 1 4 -1 */

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

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...