Submission #56072

# Submission time Handle Problem Language Result Execution time Memory
56072 2018-07-09T20:08:12 Z gabrielsimoes Mousetrap (CEOI17_mousetrap) C++17
0 / 100
1141 ms 61548 KB
#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

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 time Memory Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 24 ms 23948 KB Output is correct
3 Correct 22 ms 23948 KB Output is correct
4 Correct 25 ms 23948 KB Output is correct
5 Incorrect 20 ms 23948 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 551 ms 59788 KB Output is correct
2 Correct 470 ms 59788 KB Output is correct
3 Incorrect 1141 ms 61548 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 24 ms 23948 KB Output is correct
3 Correct 22 ms 23948 KB Output is correct
4 Correct 25 ms 23948 KB Output is correct
5 Incorrect 20 ms 23948 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 24 ms 23948 KB Output is correct
3 Correct 22 ms 23948 KB Output is correct
4 Correct 25 ms 23948 KB Output is correct
5 Incorrect 20 ms 23948 KB Output isn't correct
6 Halted 0 ms 0 KB -