Submission #570830

# Submission time Handle Problem Language Result Execution time Memory
570830 2022-05-31T10:41:36 Z Shin Mousetrap (CEOI17_mousetrap) C++14
25 / 100
787 ms 89828 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) {
  if ((int) adj[u].size() == 1) {
    return;
  }
  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(m, t);
  cout << dp[m];
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 290 ms 80444 KB Output is correct
2 Correct 312 ms 83284 KB Output is correct
3 Correct 752 ms 89748 KB Output is correct
4 Correct 397 ms 71564 KB Output is correct
5 Correct 774 ms 89708 KB Output is correct
6 Correct 787 ms 89828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47188 KB Output isn't correct
2 Halted 0 ms 0 KB -