답안 #417799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417799 2021-06-04T10:11:18 Z egekabas Mousetrap (CEOI17_mousetrap) C++14
45 / 100
1101 ms 64032 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];
 
int ans[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 maxi = {0, 0};
    int edgecnt = 0;
    for(auto u : g[v])
        if(u != prt && trap[u] == 0){
            if(dp[u] >= maxi.ff){
                maxi.ss = maxi.ff;
                maxi.ff = dp[u];
            }
            else if(dp[u] >= maxi.ss)
                maxi.ss = dp[u];
            ++edgecnt;
        }
    dp[v] = edgecnt+maxi.ss;
    ans[v] = edgecnt;
    if(v == m)
        ans[v] += maxi.ss;
    for(auto u : g[v])
        if(u != prt && trap[u]){
            dp[v] += dp[u];
            ans[v] += ans[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 << ans[m] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23816 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23720 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 15 ms 23812 KB Output is correct
8 Correct 14 ms 23800 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 62916 KB Output is correct
2 Correct 348 ms 58964 KB Output is correct
3 Correct 1101 ms 64024 KB Output is correct
4 Correct 489 ms 43928 KB Output is correct
5 Correct 1056 ms 64024 KB Output is correct
6 Correct 1077 ms 64032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23816 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23720 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 15 ms 23812 KB Output is correct
8 Correct 14 ms 23800 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Incorrect 16 ms 23808 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23816 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23720 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 15 ms 23812 KB Output is correct
8 Correct 14 ms 23800 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 389 ms 62916 KB Output is correct
12 Correct 348 ms 58964 KB Output is correct
13 Correct 1101 ms 64024 KB Output is correct
14 Correct 489 ms 43928 KB Output is correct
15 Correct 1056 ms 64024 KB Output is correct
16 Correct 1077 ms 64032 KB Output is correct
17 Incorrect 16 ms 23808 KB Output isn't correct
18 Halted 0 ms 0 KB -