Submission #1067887

#TimeUsernameProblemLanguageResultExecution timeMemory
1067887PlurmTorrent (COI16_torrent)C++11
69 / 100
100 ms27740 KiB
#include <bits/stdc++.h> using namespace std; vector<int> g[300005]; int dep[300005]; int chcnt[300005]; int col[300005]; int dp[300005]; int dfs(int u, int p = -1) { vector<int> vec; for (int v : g[u]) { if (v == p) continue; dfs(v, u); vec.push_back(dp[v]); } sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++) { dp[u] = max(dp[u], vec[i] + i + 1); } return dp[u]; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, a, b; cin >> n >> a >> b; if (a == b || n < 2) while (true) ; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } memset(dep, 0x3f, sizeof(dep)); dep[a] = dep[b] = 0; col[a] = 0; col[b] = 1; queue<int> q; q.push(a); q.push(b); while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) { if (dep[v] > dep[u] + 1) { dep[v] = dep[u] + 1; q.push(v); col[v] = col[u]; } } } for (int i = 1; i <= n; i++) { for (int j : g[i]) { if (col[j] != col[i]) { g[i].erase(find(g[i].begin(), g[i].end(), j)); break; } } } cout << max(dfs(a), dfs(b)) << endl; return 0; }

Compilation message (stderr)

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