# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103817 | luciocf | Mousetrap (CEOI17_mousetrap) | C++14 | 455 ms | 64012 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 maxn = 1e6+10;
typedef pair<int, int> pii;
int n, t, m;
int ans;
int atual;
int sz[maxn], pai[maxn];
vector<int> grafo[maxn];
int dfs(int u, int p)
{
sz[u] = 1;
for (auto v: grafo[u])
{
if (v == p) continue;
pai[v] = u;
sz[u] += dfs(v, u);
}
return sz[u];
}
void solve(int u, int p)
{
for (int i = 0; i < (int)grafo[u].size()-1; i++)
{
int v = grafo[u][i];
if (i%2 == 0)
{
ans++;
continue;
}
solve(v, u);
}
ans++;
}
bool comp(int a, int b)
{
if (a == pai[atual]) return 0;
if (b == pai[atual]) return 1;
if (atual == m && a == t) return 0;
if (atual == m && b == t) return 1;
return sz[a] > sz[b];
}
int main(void)
{
scanf("%d %d %d", &n, &t, &m);
for (int i = 1; i < n; i++)
{
int u, v;
scanf("%d %d", &u, &v);
grafo[u].push_back(v); grafo[v].push_back(u);
}
dfs(m, 0);
for (int i = 1; i <= n; i++)
{
atual = i;
sort(grafo[i].begin(), grafo[i].end(), comp);
}
solve(m, 0);
printf("%d\n", ans);
}
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... |