답안 #1053599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053599 2024-08-11T14:10:52 Z Ejen Mousetrap (CEOI17_mousetrap) C++14
25 / 100
464 ms 86104 KB
#include <bits/stdc++.h>

#define el '\n'
#define fu(i, a, b) for (long long i = a; i <= b; ++i)
#define fd(i, a, b) for (long long i = a; i >= b; --i)
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define sz(v)  (ll)v.size()
#define mask(i) (1LL << i)
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll Rand(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}

ll last(ll msk)    {return msk & (-msk);}
ll pop_cnt(ll msk) {return __builtin_popcountll(msk);}
ll ctz(ll msk)     {return __builtin_ctzll(msk);}
ll lg(ll msk)      {return 63 - __builtin_clzll(msk);}

template<class T1, class T2>
    bool maximize(T1 &a, T2 b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
    }

template<class T1, class T2>
    bool minimize(T1 &a, T2 b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
    }

template<class T>
    void print(T &a, string sep = " ", string stop = "\n") {
        for (auto x : a) cout << x << sep;
        cout << stop;
    }

template<class T>
    void compress(vector<T> &v) {
        sort(all(v));
        v.resize(unique(all(v)) - v.begin());
    }

const long long N = 1e6 + 27, base = 311, inf = 2e18, mod = 1e9 + 19972207;

ll n, t, m, timer;
ll a[N], f[N], trace[N], par[N];
vector<ll> adj[N];

void update(ll &a, ll &b, ll c) {
    if (a < c) {
        b = a;
        a = c;
    }
    else maximize(b, c);
}

void dfs(ll u, ll p) {
    ll fi = 0, se = 0;
    f[u] = sz(adj[u]) - 1;
    for (ll v : adj[u]) {
        if (v == p || v == t) continue;
        dfs(v, u);
        update(fi, se, f[v]);
    }
    f[u] += se;
}

signed main() {
    // freopen("brentford40mu.inp", "r", stdin);
    // freopen("brentford40mu.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t >> m;
    if (t == m) return cout << 0, 0;
    fu(i, 2, n) {
        ll u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(m, 0);
    cout << f[m];
    
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 74504 KB Output is correct
2 Correct 152 ms 70480 KB Output is correct
3 Correct 368 ms 73040 KB Output is correct
4 Correct 140 ms 56332 KB Output is correct
5 Correct 464 ms 86104 KB Output is correct
6 Correct 408 ms 86104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -