Submission #1047421

# Submission time Handle Problem Language Result Execution time Memory
1047421 2024-08-07T12:47:20 Z Abito Beech Tree (IOI23_beechtree) C++17
0 / 100
53 ms 30812 KB
#include "beechtree.h"
#include <bits/stdc++.h>
#define pb push_back
#define elif else if
#define ep insert
using namespace std;
const int N=2e5+5;
int a[N],c[N],p[N],n,mxd[N],dis[N];
vector<int> adj[N],s;
void getmxd(int x){
    if (x) dis[x]=dis[p[x]]+1;
    mxd[x]=dis[x];
    for (auto u:adj[x]){
        getmxd(u);
        mxd[x]=max(mxd[x],mxd[u]);
    }return;
}
void getsub(int x){
    s.pb(x);
    for (auto u:adj[x]) getsub(u);
    return;
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
    n=N;
    vector<int> ans(n,0);
    for (int i=0;i<n;i++) p[i]=P[i],c[i]=C[i];
    for (int i=1;i<n;i++) adj[p[i]].pb(i);
    getmxd(0);
    for (int i=0;i<n;i++){
        if (adj[i].empty()) ans[i]=1;
        elif (mxd[i]-dis[i]==1){
            set<int> s;
            for (auto u:adj[i]) s.ep(c[u]);
            if (s.size()==adj[i].size()) ans[i]=1;
        }
    }
    for (int i=0;i<n;i++){
        s.clear();
        if (mxd[i]-dis[i]!=2) continue;
        getsub(i);
        set<int> par;
        bool ok=true;
        for (int i=1;i<s.size();i++) par.ep(p[s[i]]),ok&=ans[s[i]];
        if (par.size()>2 || !ok) continue;
        map<int,int> mp;
        for (int i=1;i<s.size();i++) mp[c[s[i]]]++;
        for (int j=s.size()-1;j>0;j--){
            if (mp[c[s[j]]]==1 && p[s[j]]!=i) ok=0;
        }
        ans[i]=ok;
    }
    return ans;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int i=1;i<s.size();i++) par.ep(p[s[i]]),ok&=ans[s[i]];
      |                      ~^~~~~~~~~
beechtree.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i=1;i<s.size();i++) mp[c[s[i]]]++;
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Incorrect 1 ms 8820 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Incorrect 1 ms 8820 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8792 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 53 ms 30812 KB Output is correct
6 Correct 52 ms 30804 KB Output is correct
7 Incorrect 2 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '0', found: '1'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8792 KB Output is correct
8 Correct 1 ms 8812 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 1 ms 8804 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Incorrect 2 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8792 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8792 KB Output is correct
8 Correct 1 ms 8812 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 1 ms 8804 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Incorrect 2 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -