# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43033 | RayaBurong25_1 | Mousetrap (CEOI17_mousetrap) | C++14 | 1321 ms | 122688 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 <stdio.h>
#include <vector>
std::vector<int> AdjList[1000005];
int PhaseII[1000005];
int m, t;
void calcPhaseII(int u, int pa)
{
int i, v, s = AdjList[u].size();
if (pa == t)
PhaseII[u] = s - 3;
else if (s == 1 || s == 2)
PhaseII[u] = 1;
else
PhaseII[u] = s - 2;
PhaseII[u] += PhaseII[pa];
// printf("u%d PhaseII%d\n", u, PhaseII[u]);
for (i = 0; i < s; i++)
{
v = AdjList[u][i];
if (v != pa)
calcPhaseII(v, u);
}
}
int PhaseI[1000005];
int min(int a, int b)
{
return (a < b)?a:b;
}
void calcPhaseI(int u, int pa)
{
int i, v, s = AdjList[u].size();
int p = PhaseII[u], q = PhaseII[u];
for (i = 0; i < s; i++)
{
v = AdjList[u][i];
if (v != pa)
{
calcPhaseI(v, u);
if (PhaseI[v] >= p)
{
q = p;
p = PhaseI[v];
}
else if (PhaseI[v] >= q)
q = PhaseI[v];
}
}
if (s == 1)
PhaseI[u] = q;
else
PhaseI[u] = 1 + q;
// printf("u%d PhaseI%d\n", u, PhaseI[u]);
}
int main()
{
int n;
scanf("%d %d %d", &n, &t, &m);
int i, u, v;
for (i = 0; i < n - 1; i++)
{
scanf("%d %d", &u, &v);
AdjList[u].push_back(v);
AdjList[v].push_back(u);
}
calcPhaseII(m, t);
calcPhaseI(m, t);
printf("%d", PhaseI[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... |