Submission #417794

# Submission time Handle Problem Language Result Execution time Memory
417794 2021-06-04T09:59:03 Z egekabas Mousetrap (CEOI17_mousetrap) C++14
25 / 100
1073 ms 73436 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<int, int> pii;
typedef pair<ld, ld> pld;
int n, t, m;
vector<int> g[1000009];
int trap[1000009];
int dp[1000009];

void dfs(int v, int 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;
        }
    pii mini = {0, 0};
    int edgecnt = 0;
    for(auto u : g[v])
        if(u != prt && trap[u] == 0){
            if(dp[u] >= mini.ff){
                mini.ss = mini.ff;
                mini.ff = dp[u];
            }
            else if(dp[u] >= mini.ss)
                mini.ss = dp[u];
            ++edgecnt;
        }
    dp[v] = edgecnt-1;
    dp[v] += mini.ss+1;
    for(auto u : g[v])
        if(u != prt && trap[u])
            dp[v] += dp[u];
}
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(int i = 0; i < n-1; ++i){
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(m, 0);
    cout << dp[m] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Incorrect 15 ms 23816 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 362 ms 72364 KB Output is correct
2 Correct 329 ms 67524 KB Output is correct
3 Correct 1054 ms 73340 KB Output is correct
4 Correct 465 ms 48400 KB Output is correct
5 Correct 1045 ms 73436 KB Output is correct
6 Correct 1073 ms 73324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Incorrect 15 ms 23816 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Incorrect 15 ms 23816 KB Output isn't correct
6 Halted 0 ms 0 KB -