Submission #43029

#TimeUsernameProblemLanguageResultExecution timeMemory
43029RayaBurong25_1Mousetrap (CEOI17_mousetrap)C++14
0 / 100
482 ms76540 KiB
#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 (stderr)

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);
                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...