Submission #419020

# Submission time Handle Problem Language Result Execution time Memory
419020 2021-06-06T10:42:44 Z egekabas Mousetrap (CEOI17_mousetrap) C++14
45 / 100
3333 ms 90104 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n, t, m;
vector<ll> g[1000009];
ll trap[1000009];
ll dp[1000009];
ll edgecnt[1000009];

void dfs(ll v, ll prt){
    if(v == t){
        trap[v] = 1;
        return;
    }
    for(auto u : g[v])
        if(u != prt){
            dfs(u, v);
            if(trap[u])
                trap[v] = 1;
            else
                ++edgecnt[v];
        }
    dp[v] = edgecnt[v];
    for(auto u : g[v])
        if(u != prt && trap[u])
            dp[v] += dp[u];
}
ll getans(ll v, ll prt, ll curval){
    if(v == t) return 0;
    if(trap[v] == 0)
        curval -= edgecnt[v];
    if(curval < 0){
        //cout << v << ' ' << 1e9 << '\n';
        return 1e9;
    }
    ll sum = 0;
    for(auto u : g[v])
        if(u != prt){
            if(trap[u] == 0)
                sum += min(1LL, getans(u, v, curval));
            else
                sum += getans(u, v, curval);
        }
            
    //cout << v << ' ' << min((ll)1e9, max(sum-1, 0LL)) << '\n';
    return min((ll)1e9, max(sum-1, 0LL));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n >> t >> m;
    for(ll i = 0; i < n-1; ++i){
        ll x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(m, 0);
    ll l = 0, r = n;
    while(l < r){
        ll mid = (l+r)/2;
        if(getans(m, 0, mid-dp[m]) == 0)
            r = mid;
        else
            l = mid+1;
    }
    cout << l << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 13 ms 23788 KB Output is correct
3 Correct 15 ms 23776 KB Output is correct
4 Correct 13 ms 23800 KB Output is correct
5 Correct 14 ms 23816 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 15 ms 23788 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 74596 KB Output is correct
2 Correct 502 ms 69504 KB Output is correct
3 Correct 3267 ms 76840 KB Output is correct
4 Correct 1510 ms 56804 KB Output is correct
5 Correct 3333 ms 90104 KB Output is correct
6 Correct 3243 ms 90044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 13 ms 23788 KB Output is correct
3 Correct 15 ms 23776 KB Output is correct
4 Correct 13 ms 23800 KB Output is correct
5 Correct 14 ms 23816 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 15 ms 23788 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 13 ms 23812 KB Output is correct
12 Correct 15 ms 23872 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 14 ms 23888 KB Output is correct
15 Correct 14 ms 23932 KB Output is correct
16 Incorrect 15 ms 23836 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23772 KB Output is correct
2 Correct 13 ms 23788 KB Output is correct
3 Correct 15 ms 23776 KB Output is correct
4 Correct 13 ms 23800 KB Output is correct
5 Correct 14 ms 23816 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 15 ms 23788 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 557 ms 74596 KB Output is correct
12 Correct 502 ms 69504 KB Output is correct
13 Correct 3267 ms 76840 KB Output is correct
14 Correct 1510 ms 56804 KB Output is correct
15 Correct 3333 ms 90104 KB Output is correct
16 Correct 3243 ms 90044 KB Output is correct
17 Correct 13 ms 23812 KB Output is correct
18 Correct 15 ms 23872 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 14 ms 23888 KB Output is correct
21 Correct 14 ms 23932 KB Output is correct
22 Incorrect 15 ms 23836 KB Output isn't correct
23 Halted 0 ms 0 KB -