Submission #1083528

# Submission time Handle Problem Language Result Execution time Memory
1083528 2024-09-03T11:46:49 Z SamueleVid Beech Tree (IOI23_beechtree) C++17
0 / 100
2000 ms 34744 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MAXN = 2e5 + 5;
constexpr int MAXM = 2e5 + 5;

int depth[MAXN];
vector<int> adj[MAXN];
vector<int> P;
vector<int> C;
set<int> colori_prof[3];
int numero[3];

void dfs2(int u) {
    // cout << "visito " << u << " con depth " << depth[u] << '\n';
    colori_prof[depth[u]].insert(C[u]);
    // cout << "aumento numero[depth[u]] da " << numero[depth[u]] << " a ";
    numero[depth[u]] ++;
    // cout << numero[depth[u]] << '\n';

    // cout << "vicini di " << u << " :";
    // for (auto x : adj[u]) {
    //     cout << x << " ";
    // }
    // cout << '\n';

    for (auto x : adj[u]) {
        if (x == P[u]) continue;
        depth[x] = depth[u] + 1;
        dfs2(x);
    }
}

vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) {
    :: P = P;
    :: C = C;

    fill(colori_prof, colori_prof + 3, set<int>());
    fill(numero, numero + 3, 0);
    fill(adj, adj + MAXN, vector<int>());

    for (int i = 1; i < N; i ++) {
        adj[P[i]].push_back(i);
        adj[i].push_back(P[i]);
    }

    depth[0] = 0;
    dfs2(0);

    vector<int> res(N, 1);
    
    bool condivide_uno = 0;
    for (auto x : colori_prof[2]) {
        if (colori_prof[1].count(x)) condivide_uno = 1;
    }

    // cout << "colori_prof[2].size() : " << colori_prof[2].size() << '\n';
    // cout << "condivide_uno : " << condivide_uno << '\n';
    // cout << "colori_prof[1].size() : " << colori_prof[1].size() << '\n';
    // cout << "numero[1] : " << numero[1] << '\n';

    res[0] = 0;

    if ((colori_prof[2].size() == 1 && condivide_uno) && colori_prof[1].size() == numero[1]) {
        res[0] = 1;
    }

    if (numero[2] == 0 && colori_prof[1].size() == numero[1]) {
        res[0] = 1; 
    }

    if (numero[1] == 0) res[0] = 1;

    return res;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:64:80: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     if ((colori_prof[2].size() == 1 && condivide_uno) && colori_prof[1].size() == numero[1]) {
      |                                                          ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
beechtree.cpp:68:49: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |     if (numero[2] == 0 && colori_prof[1].size() == numero[1]) {
      |                           ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Runtime error 7 ms 9996 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Execution timed out 2096 ms 4956 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Execution timed out 2096 ms 4956 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Incorrect 3 ms 4952 KB 2nd lines differ - on the 4th token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 4 ms 4956 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Runtime error 55 ms 34744 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Runtime error 7 ms 9996 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 4 ms 4956 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Runtime error 6 ms 10076 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Runtime error 7 ms 9996 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 4 ms 4956 KB Output is correct
4 Correct 4 ms 4956 KB Output is correct
5 Runtime error 6 ms 10076 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Runtime error 7 ms 9996 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -