Submission #56071

#TimeUsernameProblemLanguageResultExecution timeMemory
56071gabrielsimoesMousetrap (CEOI17_mousetrap)C++17
0 / 100
1227 ms61476 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6+10; int n, t, s; vector<int> g[MAXN]; bool good[MAXN]; int ans[MAXN]; void dfs(int cur, int pre) { if (cur == t) return; int ansGood = -1; vector<int> v; for (int nx : g[cur]) { if (nx != pre) { dfs(nx, cur); good[cur] |= good[nx]; if (good[nx]) ansGood = ans[nx]; else v.push_back(ans[nx]); } } sort(v.rbegin(), v.rend()); int &ret = ans[cur]; for (int i = 0; i < v.size(); i++) { if (i % 2) ret += v[i]; else ret++; } if (!good[cur]) ret++; else ret += ansGood; // printf("ans[%d] == %d\n", cur, ans[cur]); } int main() { scanf("%d %d %d", &n, &t, &s); for (int i = 1,a,b; i < n; i++) { scanf("%d %d", &a, &b); g[a].push_back(b); g[b].push_back(a); } good[t] = true; dfs(s, s); printf("%d\n", ans[s]); }

Compilation message (stderr)

mousetrap.cpp: In function 'void dfs(int, int)':
mousetrap.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); i++) {
                     ~~^~~~~~~~~~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &t, &s);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         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...