# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
131528 | SamAnd | Mousetrap (CEOI17_mousetrap) | C++17 | 1107 ms | 73464 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.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, t, m;
vector<int> a[N];
bool c[N];
void dfs0(int x, int p)
{
if (x == t)
{
c[x] = true;
return;
}
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i];
if (h == p)
continue;
dfs0(h, x);
if (c[h])
{
c[x] = true;
return;
}
}
}
int dp[N];
void dfs(int x, int p)
{
vector<int> v;
int vv = 0;
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i];
if (h == p)
continue;
dfs(h, x);
if (!c[h])
v.push_back(dp[h]);
}
sort(v.begin(), v.end());
for (int i = v.size() - 2; i >= 0; i -= 2)
{
dp[x] += v[i];
}
dp[x] += v.size();
}
int main()
{
//freopen("input.txt", "r", stdin);
scanf("%d%d%d", &n, &t, &m);
for (int i = 0; i < n - 1; ++i)
{
int x, y;
scanf("%d%d", &x, &y);
a[x].push_back(y);
a[y].push_back(x);
}
dfs0(m, m);
dfs(m, m);
int ans = 0;
for (int x = 1; x <= n; ++x)
{
if (c[x])
ans += dp[x];
}
cout << ans << endl;
return 0;
}
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... |