Submission #570826

# Submission time Handle Problem Language Result Execution time Memory
570826 2022-05-31T10:38:50 Z Shin Mousetrap (CEOI17_mousetrap) C++14
0 / 100
303 ms 78488 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

const int N = 2e6 + 7;
int n, m, t;
int dp[N];
vector<int> adj[N];

void dfs(int u, int p) {
  int F = 0, S = 0;
  for (int v: adj[u]) if (v != p) {
    dfs(v, u);
    if (F < dp[v]) {
      S = F;
      F = dp[v];
    } else {
      maximize(S, dp[v]);
    }
  }
  dp[u] = (int) adj[u].size() + S - 1;
}

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> t >> m;
  for (int i = 1; i < n; i ++) {
    int u, v; cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  } 
  dfs(t, m);
  cout << dp[t];
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 47188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 303 ms 78488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 47188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 47188 KB Output isn't correct
2 Halted 0 ms 0 KB -