제출 #506120

#제출 시각아이디문제언어결과실행 시간메모리
506120JomnoiTorrent (COI16_torrent)C++17
69 / 100
360 ms29072 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 3e5 + 10; const int INF = 1e9 + 7; vector <int> arr; vector <int> adj[N]; bool find(int u, int p, int x) { if(u == x) { arr.push_back(u); return 1; } for(auto v : adj[u]) { if(v == p) { continue; } if(find(v, u, x) == true) { arr.emplace_back(u); return true; } } return false; } int dfs(int u, int p, int x) { vector <int> child; for(auto v : adj[u]) { if(v == p || v == x) { continue; } child.push_back(dfs(v, u, x)); } sort(child.rbegin(), child.rend()); int res = 0; for(int i = 1; i <= child.size(); i++) { res = max(res, child[i - 1] + i); } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, a, b; cin >> n >> a >> b; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].emplace_back(v); adj[v].emplace_back(u); } find(a, -1, b); int l = 0, r = arr.size() - 2; int ans = INF; while(l <= r) { int mid = (l + r) / 2; int L = dfs(a, -1, arr[mid]); int R = dfs(b, -1, arr[mid + 1]); ans = min(ans, max(L, R)); if(L < R) { l = mid + 1; } else { r = mid - 1; } } cout << ans; return 0; }

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

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