Submission #131529

#TimeUsernameProblemLanguageResultExecution timeMemory
131529SamAndMousetrap (CEOI17_mousetrap)C++17
0 / 100
1049 ms60280 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000006; int n, t, m; vector<int> a[N]; bool c[N]; void dfs0(int x, int p) { if (x == t) { c[x] = true; return; } for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (h == p) continue; dfs0(h, x); if (c[h]) { c[x] = true; return; } } } int dp[N]; void dfs(int x, int p) { if (x == t) return; vector<int> v; int vv = 0; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (h == p) continue; dfs(h, x); if (!c[h]) v.push_back(dp[h]); } sort(v.begin(), v.end()); for (int i = v.size() - 2; i >= 0; i -= 2) { dp[x] += v[i]; } dp[x] += v.size(); } int main() { //freopen("input.txt", "r", stdin); scanf("%d%d%d", &n, &t, &m); for (int i = 0; i < n - 1; ++i) { int x, y; scanf("%d%d", &x, &y); a[x].push_back(y); a[y].push_back(x); } dfs0(m, m); dfs(m, m); int ans = 0; for (int x = 1; x <= n; ++x) { if (c[x]) ans += dp[x]; } cout << ans << endl; return 0; }

Compilation message (stderr)

mousetrap.cpp: In function 'void dfs0(int, int)':
mousetrap.cpp:16:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
mousetrap.cpp: In function 'void dfs(int, int)':
mousetrap.cpp:37:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
mousetrap.cpp:36:9: warning: unused variable 'vv' [-Wunused-variable]
     int vv = 0;
         ^~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:57:10: 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:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...