Submission #541516

# Submission time Handle Problem Language Result Execution time Memory
541516 2022-03-23T17:36:54 Z adespawn Mousetrap (CEOI17_mousetrap) C++14
45 / 100
818 ms 60984 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> sc[1000006];
bool isS[1000006];
bool odw[1000006];

long long solve(int w, int f, int a = 1)
{

    priority_queue<int> k;
    for (auto i : sc[w])
    {
        if (i == f || isS[i])
            continue;
        k.push(solve(i, w));
    }
    while (k.size() < a + 1)
        k.push(0);
    for (int i = 0; i < a; i++)
        k.pop();
    return sc[w].size() - 1 + k.top();
}

int n, m, k;

stack<pair<int, int>> s;

long long nw;

int dfs(int w, int f = 0, int g = 1)
{
    if (w == m)
        return 1;
    for (auto i : sc[w])
    {
        if (i == f)
            continue;
        int x = dfs(i, w, g + 1);
        if (x == 0)
            continue;
        isS[i] = 1;
        nw = max(x + solve(w, f, g) - (f != 0), nw);
        return x + sc[w].size() - 2;
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> k;
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        sc[a].push_back(b);
        sc[b].push_back(a);
    }
    dfs(k);
    cout << nw - 1 << '\n';
    // s.push({0, 0});
    // cout << solve(k, m);
}

Compilation message

mousetrap.cpp: In function 'long long int solve(int, int, int)':
mousetrap.cpp:18:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |     while (k.size() < a + 1)
      |            ~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 15 ms 23792 KB Output is correct
3 Correct 12 ms 23812 KB Output is correct
4 Correct 12 ms 23816 KB Output is correct
5 Correct 14 ms 23772 KB Output is correct
6 Correct 13 ms 23748 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 14 ms 23728 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 349 ms 59756 KB Output is correct
2 Correct 317 ms 57196 KB Output is correct
3 Correct 818 ms 60848 KB Output is correct
4 Correct 367 ms 45520 KB Output is correct
5 Correct 780 ms 60984 KB Output is correct
6 Correct 817 ms 60952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 15 ms 23792 KB Output is correct
3 Correct 12 ms 23812 KB Output is correct
4 Correct 12 ms 23816 KB Output is correct
5 Correct 14 ms 23772 KB Output is correct
6 Correct 13 ms 23748 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 14 ms 23728 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23792 KB Output is correct
11 Incorrect 13 ms 23816 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 15 ms 23792 KB Output is correct
3 Correct 12 ms 23812 KB Output is correct
4 Correct 12 ms 23816 KB Output is correct
5 Correct 14 ms 23772 KB Output is correct
6 Correct 13 ms 23748 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 14 ms 23728 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23792 KB Output is correct
11 Correct 349 ms 59756 KB Output is correct
12 Correct 317 ms 57196 KB Output is correct
13 Correct 818 ms 60848 KB Output is correct
14 Correct 367 ms 45520 KB Output is correct
15 Correct 780 ms 60984 KB Output is correct
16 Correct 817 ms 60952 KB Output is correct
17 Incorrect 13 ms 23816 KB Output isn't correct
18 Halted 0 ms 0 KB -