Submission #43033

# Submission time Handle Problem Language Result Execution time Memory
43033 2018-03-08T07:28:52 Z RayaBurong25_1 Mousetrap (CEOI17_mousetrap) C++14
25 / 100
1321 ms 122688 KB
#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

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:57:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &t, &m);
                                  ^
mousetrap.cpp:61:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
                               ^
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 477 ms 63144 KB Output is correct
2 Correct 428 ms 71344 KB Output is correct
3 Correct 1321 ms 89580 KB Output is correct
4 Correct 569 ms 89580 KB Output is correct
5 Correct 1235 ms 109484 KB Output is correct
6 Correct 1253 ms 122688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -