답안 #973205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973205 2024-05-01T16:02:38 Z efedmrlr Mousetrap (CEOI17_mousetrap) C++17
25 / 100
727 ms 73468 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;


#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 1e6 + 5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,t,m;

vector<int> dp(N, 0);
vector<vector<int> > adj(N, vector<int>());

void dfs(int node, int par) {
    for(auto c : adj[node]) {
        if(c == par) continue;
        dfs(c, node);
    }
    array<int, 2> mx = {0, 0};
    for(auto c : adj[node]) {
        if(c == par) continue;
        if(dp[c] > mx[0]) {
            swap(mx[0], mx[1]);
            mx[0] = dp[c];
        }
        else if(dp[c] > mx[1]) {
            mx[1] = dp[c];
        }
    }
    dp[node] = mx[1] + adj[node].size() - 1; 

}

inline void solve() {
    cin>>n>>t>>m;
    REP(i, n - 1) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(m, t);
    cout << dp[m] << "\n";
}
 
signed main() {

    fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 27736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 59160 KB Output is correct
2 Correct 238 ms 67808 KB Output is correct
3 Correct 669 ms 73312 KB Output is correct
4 Correct 316 ms 50496 KB Output is correct
5 Correct 727 ms 73464 KB Output is correct
6 Correct 663 ms 73468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 27736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 27736 KB Output isn't correct
2 Halted 0 ms 0 KB -