Submission #131529

# Submission time Handle Problem Language Result Execution time Memory
131529 2019-07-17T08:49:12 Z SamAnd Mousetrap (CEOI17_mousetrap) C++17
0 / 100
1049 ms 60280 KB
#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

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 time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 24 ms 23800 KB Output is correct
5 Incorrect 23 ms 23800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 480 ms 59040 KB Output is correct
2 Correct 436 ms 55584 KB Output is correct
3 Incorrect 1049 ms 60280 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 24 ms 23800 KB Output is correct
5 Incorrect 23 ms 23800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 24 ms 23800 KB Output is correct
5 Incorrect 23 ms 23800 KB Output isn't correct
6 Halted 0 ms 0 KB -