Submission #303057

#TimeUsernameProblemLanguageResultExecution timeMemory
303057Kenzo_1114Mousetrap (CEOI17_mousetrap)C++17
25 / 100
926 ms73592 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 1000010; int n, t, m, dp[MAXN]; vector<int> graph[MAXN]; void dfs(int v, int p) { int mx[2] = {-1, -1}; for(int i = 0; i < graph[v].size(); i++) { int u = graph[v][i]; if(u == p) continue; dfs(u, v); if(dp[u] >= mx[0]) mx[1] = mx[0], mx[0] = dp[u]; else if(dp[u] > mx[1]) mx[1] = dp[u]; } dp[v] = ((int) graph[v].size() == 2) ? 1 : mx[1] + graph[v].size() - 1; if((int) graph[v].size() == 1) dp[v] = 0; } int main () { scanf("%d %d %d", &n, &t, &m); for(int i = 0, u, v; i < n - 1; i++) { scanf("%d %d", &u, &v); graph[u].push_back(v); graph[v].push_back(u); } if(t == m || (int) graph[m].size() == 0) { printf("0\n"); return 0; } dfs(t, t); // for(int i = 1; i <= n; i++) printf("dp[%d] = %d\n", i, dp[i]); printf("%d\n", dp[m]); }

Compilation message (stderr)

mousetrap.cpp: In function 'void dfs(int, int)':
mousetrap.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i = 0; i < graph[v].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%d %d %d", &n, &t, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |   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...