Submission #1305374

#TimeUsernameProblemLanguageResultExecution timeMemory
1305374baktrrTeam Coding (EGOI24_teamcoding)C++20
0 / 100
19 ms14472 KiB
/**
  III     U   U  N   N  DDDD   EEEEE  RRRR   SSSS  TTTTT  AAAAA  N   N  DDDD      I  TTTTT     N   N   OOO   W   W
   I      U   U  NN  N  D   D  E      R   R  S       T    A   A  NN  N  D   D     I    T       NN  N  O   O  W   W
   I      U   U  N N N  D   D  EEEE   RRRR   SSSS    T    AAAAA  N N N  D   D     I    T       N N N  O   O  W W W
   I      U   U  N  NN  D   D  E      R  R      S    T    A   A  N  NN  D   D     I    T       N  NN  O   O  WW WW
  III     UUUUU  N   N  DDDD   EEEEE  R   R  SSSS    T    A   A  N   N  DDDD      I    T       N   N   OOO   W   W
**/

//18.09.25
#include <bits/stdc++.h>

// #pragma optimize("g", on)
// #pragma GCC optimize ("inline")
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroint-loops")
// #pragma GCC optimize ("03")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
 
#define F first
#define ent '\n'
#define S second
#define no "NO\n"
#define in insert
#define yes "YES\n"
#define pb push_back
#define int long long
#define sz(w) w.size()
#define pii pair <int, int>
#define all(w) w.begin(), w.end()
#define rall(w) w.rbegin(), w.rend()
#define Yeah ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
const int MOD = 998244353, M = 4e5 + 7, N = 1e5 + 7, INF = 1e18, inf = 1e9 + 7, LOG = 20 , mod = 1e9 + 7 ;

// find_by_order idx and get s[idx], idx from 0
// order_of_key cnt of x >

// template <typename T>
// using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector <int> g[N] ;
int cnt1[N] , cnt2[N] , a[N] ;

void dfs(int v) {
    cnt1[v] = (a[v] == 0) ;
    cnt2[v] = (a[v] == 1) ;
    for(int to : g[v]) {
        dfs(to) ;
        cnt1[v] += cnt1[to] ;
        cnt2[v] += cnt2[to] ;
    }
}

void accepted() {
    int n , k ;
    cin >> n >> k ;
    int cnt = 0 ;
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i] ;
        if(a[i] == 0) {
            cnt++;
        }
    }
    for(int i = 2 ; i <= n ; i++) {
        int x ;
        cin >> x ;
        g[x + 1].pb(i) ;
    }
    dfs(1) ;
    int ans = 0 , res = 0 ;
    for(int i = 1 ; i <= n ; i++) {
        int mx = cnt1[i] + min(cnt - cnt1[i] , cnt2[i]) ;
        int mn = min(cnt - cnt1[i] , cnt2[i]) ;
        if(mx > ans || (mx == ans && mn < res)) {
            ans = mx ;
            res = mn ;
        }
        mx = cnt1[i] + min(n - cnt - cnt1[i] , cnt1[i]) ;
        mn = min(n - cnt - cnt1[i] , cnt1[i]) ;
        if(mx > ans || (mx == ans && mn < res)) {
            ans = mx ;
            res = mn ;
        }
    }

    cout << ans << ' ' << res ;
}

signed main() {
    Yeah
 
    // PLS NeverGiveUp

    // freopen("cowpatibility.in", "r", stdin) ;  
    // freopen("cowpatibility.out", "w", stdout) ;

    int T = 1 ;
    // cin >> T ;
    while(T--) {
        accepted();
        cout << endl ;
    }
}

/**

**/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...