| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1055705 | shjeong | Beech Tree (IOI23_beechtree) | C++17 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pi;
#define all(x) x.begin(),x.end()
#define rll(x) x.rbegin(),x.rend()
ll n, m;
vector<ll> p, c;
vector<int> ans;
vector<ll> adj[202020];
void dfs(ll x){
    for(auto next : adj[x]){
        dfs(next);
    }
    set<ll> st;
    bool flag = 1;
    for(auto next : adj[x]){
        if(st.find(c[next]) != st.end()){
            flag = 0;
            break;
        }
        st.insert(c[next]);
    }
    ans[x] = flag;
    if(x==0 and flag){
        vector<pair<ll,map<ll,ll>>> v;
        for(auto next : adj[x]){
            if(!ans[next]){ans[x] = 0; return;}
            ll cnt = 0; map<ll,ll> mp;
            for(auto nnext : adj[next])cnt++, mp[c[nnext]]++;
            v.push_back({cnt,mp});
        }
        sort(rll(v));
        for(int i = 1 ; i < v.size() ; i++){
            for(auto [a,b] : v[i].second){
                if(v[i-1].second[a] < b){
                    ans[x] = 0;
                    return;
                }
                if(v[i-1].first == v[i-1].first and v[i-1].second[a] != b){
                    ans[x] = 0;
                    return;
                }
            }
        }
    }
}
