Submission #354180

# Submission time Handle Problem Language Result Execution time Memory
354180 2021-01-21T14:13:58 Z valerikk Mousetrap (CEOI17_mousetrap) C++17
0 / 100
450 ms 80288 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 7;

int n, t, m;
vector <int> g[N];
int par[N];
int sum[N];
int w[N];

void dfs(int v, int p = -1) {
  par[v] = p;
  vector <int> gg;
  for (int u : g[v]) {
    if (u != p) {
      gg.push_back(u);
      dfs(u, v);
    }
  }
  g[v].swap(gg);
}

void zhfs(int v) {
  for (int u : g[v]) {
    sum[u] = sum[v] + (int) g[v].size();
    zhfs(u);
  }
}

void wfs(int v) {
  if (g[v].size() <= 1)
    w[v] = sum[v];
  vector<int> have;
  for (int u : g[v]) {
    wfs(u);
    have.push_back(w[u]);
  }
  sort(have.rbegin(), have.rend());
  if (have.size() >= 2)
    w[v] = have[1];
}



int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> t >> m;
  --t;
  --m;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(t);
  zhfs(t);
  wfs(t);
  cout << w[m] << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 450 ms 80288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -