Submission #211386

#TimeUsernameProblemLanguageResultExecution timeMemory
211386FischerTorrent (COI16_torrent)C++14
0 / 100
306 ms23032 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; bool vis[maxn]; vector<int> g[maxn]; int n, a, b; int dp[maxn]; int dfs(int x) { vis[x] = 1; vector<int> t; for (int v : g[x]) { if (vis[v]) continue; dfs(v); t.push_back(dp[v]); } sort(t.rbegin(), t.rend()); int ans = 0; for (int i = 0; i < t.size(); ++i) { ans = max(ans, t[i] + i + 1); } dp[x] = ans; } int main() { cin >> n >> a >> b; for (int i = 1; i <= n-1; ++i) { int x, y; cin >> x >> y; g[x].push_back(y); } vis[a] = vis[b] = 1; dfs(a); dfs(b); cout << max(dp[a], dp[b]) << endl; return 0; }

Compilation message (stderr)

torrent.cpp: In function 'int dfs(int)':
torrent.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < t.size(); ++i) {
                  ~~^~~~~~~~~~
torrent.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...