Submission #912603

# Submission time Handle Problem Language Result Execution time Memory
912603 2024-01-19T16:25:44 Z Ludissey Beech Tree (IOI23_beechtree) C++17
0 / 100
1 ms 348 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
int N,M;
vector<vector<int>> child;
vector<int> C;
vector<int> P;
vector<int> outp;


std::vector<int> beechtree(int n, int m, std::vector<int> p, std::vector<int> c)
{
    N=n; M=m;
    C.assign(c.begin(), c.end());
    P.assign(p.begin(), p.end());
    child.resize(n);
    outp.resize(n,0);
    for (int i = 1; i < N; i++) child[P[i]].push_back(i);
    bool df=true;
    outp[0]=1;
    vector<pair<int,int>> childr;
    unordered_set<int> ccolors;
    for (int i = 1; i < n; i++)
    {
        if(child[i].size()==0) outp[i]=1;
        else if(P[i]==0){
            unordered_set<int> colors;
            if(ccolors.find(c[i])!=ccolors.end()) outp[0]=0;
            ccolors.insert(c[i]);
            childr.push_back({child[i].size(),i});
            outp[i]=1;
            for (auto u : child[i]) 
            {
                if(colors.find(c[u])!=colors.end()) { outp[i]=0; df=false; break; }
                colors.insert(c[u]);
            }
        }
    }
    if(!df) { outp[0]=0; return {outp}; }
    sort(childr.begin(), childr.end(),greater<pair<int,int>>());
    unordered_set<int> colors;
    for (int i = 0; i < (int)child[0].size(); i++)
    {
        for (auto u : child[childr[i].second]) 
        {
            if(ccolors.find(c[u])==ccolors.end()) { outp[0]=0; break; }
            if(colors.find(c[u])==colors.end()&&i>0) { outp[0]=0; break; }
            colors.insert(c[u]);
        }
        if(outp[0]==0) break;
    }
    
    return {outp};
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB 2nd lines differ - on the 3rd token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB 2nd lines differ - on the 3rd token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -