# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1028489 | Thanhs | Mousetrap (CEOI17_mousetrap) | C++14 | 538 ms | 99664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define double long double
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define fi first
#define se second
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 1e6 + 5;
const int mod = 1e6 + 3;
const int inf = 1e9 + 1;
vector<int> g[NM];
int n, t, m, w[NM], dep[NM], par[NM];
void dfs(int u = t, int p = 0)
{
int be = 0, sb = 0;
for (auto v : g[u])
{
if (v == p)
continue;
dep[v] = dep[u] + 1;
par[v] = u;
dfs(v, u);
if (be < w[v])
{
sb = be;
be = w[v];
}
else if (sb < w[v])
sb = w[v];
}
if (g[u].size() - !!p == 0)
w[u] = 0;
else if (g[u].size() - !!p == 1)
w[u] = 1;
else
w[u] += sb + g[u].size() - !!p;
}
signed main()
{
if (fopen("in.txt", "r")) {
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
}
fastIO
cin >> n >> t >> m;
for (int i = 2; i <= n; i++)
{
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs();
cout << w[m];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |