Submission #1092992

# Submission time Handle Problem Language Result Execution time Memory
1092992 2024-09-25T15:40:57 Z Jakub_Wozniak Village (BOI20_village) C++17
0 / 100
2 ms 2792 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define nd second
#define st first
typedef pair<ll, ll> pii;
const int maxn = (1e+5)+9;
vector <ll> t[maxn];
ll siz[maxn];
ll dep[maxn];
ll sumdep[maxn];
ll cen = -1;
ll dp[maxn][2];
ll N;

void DFS(int v , int o)
{
    ll ind = -1;
    ll p , res = 0; bool B = 0; ll mini = (1e+18);
    for(int i = 0 ;i < t[v].size();i++) 
    {
        p = t[v][i];
        if(p == o)continue;
        DFS(p,v);
        if(dp[p][1]+2 <= dp[p][0])
        {
            res += dp[p][1]+2;
            B = 1;
        }
        else
        {
            res += dp[p][0];
            if(dp[p][1]+1-dp[p][0] < mini)ind = p;
            mini = min(dp[p][1]+2-dp[p][0] , mini);
        }
    }


    dp[v][1] = res;            
    if(B == 0)
    {
        res += mini;
    }          
    dp[v][0] = res;   
    
     
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll A , B;
    cin >> N;
    for(int i = 0 ;i < N-1 ; i++)
    {
        cin >> A >> B;
        t[A].push_back(B);
        t[B].push_back(A);
    }

    if(N == 2)
    {
        cout << 2 << ' ' << 2 << '\n';
        cout << 2 << ' ' << 1 << '\n';
        cout << 2 << ' ' << 1 << '\n';
        return 0;
    }


    dep[1] = 0;
    DFS(1,-1);
    cout << dp[1][0]  << ' ' << 1 << '\n';


    return 0;
}

Compilation message

Village.cpp: In function 'void DFS(int, int)':
Village.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i = 0 ;i < t[v].size();i++)
      |                    ~~^~~~~~~~~~~~~
Village.cpp:19:8: warning: variable 'ind' set but not used [-Wunused-but-set-variable]
   19 |     ll ind = -1;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2792 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -