답안 #1068577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068577 2024-08-21T10:44:04 Z parsadox2 참나무 (IOI23_beechtree) C++17
5 / 100
65 ms 34248 KB
#include "beechtree.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
int n , col[N] , m , sbt[N] , is_path[N] , cnt[N];
vector <int> adj[N];
vector <int> all , p;

void Dfs(int v)
{
    sbt[v] = 1;
    for(auto u : adj[v])
    {
        Dfs(u);
        sbt[v] += sbt[u];
    }
    if(adj[v].size() == 1)
    {
        int c = adj[v][0];
        if(sbt[c] == 1)
            is_path[v] = col[c];
        else if(col[c] == is_path[c])
            is_path[v] = col[c];
        else
            is_path[v] = -1;
    }
    else if(adj[v].size() > 1)
    {
        is_path[v] = -1;
    }
}

void Dfs_all(int v)
{
    all.push_back(v);
    cnt[col[v]] = 0;
    for(auto u : adj[v])
        Dfs_all(u);
}

bool Solve(int v)
{
    all.clear();
    Dfs_all(v);
    sort(all.begin() , all.end());
    bool flg = false;
    do{
        for(auto u : all)
            cnt[col[u]] = 0;
        bool tmp = true;
        for(int i = 1 ; i < all.size() ; i++)
        {
            if(all[cnt[col[all[i]]]] != p[all[i]])
                tmp = false;
            cnt[col[all[i]]]++;
        }
        flg |= tmp;
    }while(next_permutation(all.begin() , all.end()));
    return flg;
}

vector<int> beechtree(int nn, int mm, vector<int> P, vector<int> C)
{
    n = nn;  
    m = mm;
    p = P;
    for(int i = 1 ; i < n ; i++)
    {
        adj[P[i]].push_back(i);
        col[i] = C[i];
    }
    Dfs(0);
    vector <int> res(n , 0);
    for(int i = 0 ; i < n ; i++)
    {
        if(is_path[i] != -1)
        {
            res[i] = true;
            continue;
        }
        //res[i] = Solve(i);
    }
    return res;
}

Compilation message

beechtree.cpp: In function 'bool Solve(int)':
beechtree.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int i = 1 ; i < all.size() ; i++)
      |                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 1 ms 6748 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Incorrect 1 ms 6748 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 65 ms 31568 KB Output is correct
8 Correct 64 ms 34248 KB Output is correct
9 Correct 1 ms 6744 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 2 ms 7000 KB Output is correct
15 Correct 2 ms 7004 KB Output is correct
16 Correct 1 ms 7004 KB Output is correct
17 Correct 60 ms 33876 KB Output is correct
18 Correct 63 ms 34128 KB Output is correct
19 Correct 60 ms 34132 KB Output is correct
20 Correct 62 ms 34128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6744 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Incorrect 1 ms 6748 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 1 ms 6748 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Incorrect 1 ms 6748 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 1 ms 6748 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Incorrect 1 ms 6748 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 1 ms 6748 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -