답안 #43029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43029 2018-03-08T07:07:58 Z RayaBurong25_1 Mousetrap (CEOI17_mousetrap) C++14
0 / 100
482 ms 76540 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] = PhaseII[pa] + s - 3;
    else if (s == 1 || s == 2)
        PhaseII[u] = PhaseII[pa] + 1;
    else
        PhaseII[u] = PhaseII[pa] + s - 2;
    // 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];
void calcPhaseI(int u, int pa)
{
    int i, v, s = AdjList[u].size();
    int p = 0, q = 0;
    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];
        }
    }
    PhaseI[u] = 1 + q + PhaseII[u];
    // 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:49: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:53:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
                               ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 482 ms 76540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -