Submission #103817

#TimeUsernameProblemLanguageResultExecution timeMemory
103817luciocfMousetrap (CEOI17_mousetrap)C++14
0 / 100
455 ms64012 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6+10; typedef pair<int, int> pii; int n, t, m; int ans; int atual; int sz[maxn], pai[maxn]; vector<int> grafo[maxn]; int dfs(int u, int p) { sz[u] = 1; for (auto v: grafo[u]) { if (v == p) continue; pai[v] = u; sz[u] += dfs(v, u); } return sz[u]; } void solve(int u, int p) { for (int i = 0; i < (int)grafo[u].size()-1; i++) { int v = grafo[u][i]; if (i%2 == 0) { ans++; continue; } solve(v, u); } ans++; } bool comp(int a, int b) { if (a == pai[atual]) return 0; if (b == pai[atual]) return 1; if (atual == m && a == t) return 0; if (atual == m && b == t) return 1; return sz[a] > sz[b]; } int main(void) { scanf("%d %d %d", &n, &t, &m); for (int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); grafo[u].push_back(v); grafo[v].push_back(u); } dfs(m, 0); for (int i = 1; i <= n; i++) { atual = i; sort(grafo[i].begin(), grafo[i].end(), comp); } solve(m, 0); printf("%d\n", ans); }

Compilation message (stderr)

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:63:7: 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:68:8: 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...