답안 #912668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912668 2024-01-19T17:38:18 Z Ludissey 참나무 (IOI23_beechtree) C++17
9 / 100
62 ms 17492 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(P[i]==0){
            childr.push_back({child[i].size(),i});
            unordered_set<int> clors;
            if(ccolors.find(c[i])!=ccolors.end()) outp[0]=0;
            ccolors.insert(c[i]);
            outp[i]=1;
            for (auto u : child[i]) 
            {
                if(clors.find(c[u])!=clors.end()) { outp[i]=0; df=false; break; } // la couleur est la meme dans un arbre
                clors.insert(c[u]);
            }
        }   
        else if(child[i].size()==0) outp[i]=1;
    }
    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++) colors.insert(c[child[0][i]]); // la couleur est la meme dans un arbre
    for (int i = 0; i < (int)childr.size(); i++)
    {
        unordered_set<int> colors2;
        for (auto u : child[childr[i].second]) 
        {
            if(colors.find(c[u])==colors.end()) { outp[0]=0; break; } // color in subtree is not in other tree
            colors.insert(c[u]);
            colors2.insert(c[u]);
        }
        colors.clear();
        colors=colors2;
        if(outp[0]==0) break;
    }
    
    return {outp};
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 2nd lines differ - on the 3rd token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 2nd lines differ - on the 3rd token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 37 ms 7664 KB Output is correct
16 Correct 33 ms 7260 KB Output is correct
17 Correct 33 ms 7252 KB Output is correct
18 Correct 47 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Incorrect 62 ms 17492 KB 2nd lines differ - on the 2nd token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -