Submission #56069

#TimeUsernameProblemLanguageResultExecution timeMemory
56069gabrielsimoesMousetrap (CEOI17_mousetrap)C++17
0 / 100
51 ms13024 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; const int MAXN = 1e5+10, MAXL = 18; int n, t, s; vector<int> g[MAXN]; bool good[MAXN]; void dfs0(int cur, int pre) { for (int nx : g[cur]) { if (nx != pre) { dfs0(nx, cur); good[cur] |= good[nx]; } } } int ans[MAXN]; void dfs1(int cur, int pre) { if (cur == t) return; int ansGood = -1; vector<int> v; for (int nx : g[cur]) { if (nx != pre) { dfs1(nx, cur); 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; } 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; dfs0(s, s); dfs1(s, s); printf("%d\n", ans[s]); }

Compilation message (stderr)

mousetrap.cpp: In function 'void dfs1(int, int)':
mousetrap.cpp:41: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:51: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:53: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...