Submission #308771

#TimeUsernameProblemLanguageResultExecution timeMemory
308771wmrmrMousetrap (CEOI17_mousetrap)C++17
0 / 100
906 ms77564 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6+10; int dp[MAX], pai[MAX]; int n,t,m; vector<int> g[MAX]; void DFS1(int v, int p) { pai[v] = p; int mx = 0; for(int i=0;i<g[v].size();i++) { int prox = g[v][i]; if(prox == p) continue; DFS1(prox,v); mx = max(mx,dp[prox]); dp[v] += 1+dp[prox]; } dp[v] -= mx; } void DFS2(int v, int f, int ans) { if(v == t) { printf("%d",ans); return; } int mx = 0; int cur = 0; for(int i=0;i<g[v].size();i++) { int prox = g[v][i]; if(prox == f || prox == pai[v]) continue; mx = max(mx,dp[prox]); cur += dp[prox]+1; } cur -= mx; DFS2(pai[v],v,ans+cur); } int main() { scanf("%d %d %d",&n,&t,&m); for(int i=1;i<n;i++) { int a,b; scanf("%d %d",&a,&b); g[a].push_back(b); g[b].push_back(a); } DFS1(t,0); DFS2(m,0,0); }

Compilation message (stderr)

mousetrap.cpp: In function 'void DFS1(int, int)':
mousetrap.cpp:12:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for(int i=0;i<g[v].size();i++)
      |              ~^~~~~~~~~~~~
mousetrap.cpp: In function 'void DFS2(int, int, int)':
mousetrap.cpp:31:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0;i<g[v].size();i++)
      |              ~^~~~~~~~~~~~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |  scanf("%d %d %d",&n,&t,&m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:47:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |   int a,b; scanf("%d %d",&a,&b);
      |            ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...