# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56072 | gabrielsimoes | Mousetrap (CEOI17_mousetrap) | C++17 | 1141 ms | 61548 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 0;
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |