Submission #841651

# Submission time Handle Problem Language Result Execution time Memory
841651 2023-09-01T19:23:54 Z Batrr Beech Tree (IOI23_beechtree) C++17
0 / 100
2000 ms 54004 KB
#include "beechtree.h"
#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;

vector<pii> g[N];
int n, m;
int ans[N];
int P[N], C[N];

vector<int> t[N];

int get(int v, int u) {
    if (g[v].size() > g[u].size())
        return -1;
    if (g[v].size() < g[u].size())
        return 1;
    for (int i = 0; i < g[v].size(); i++) {
        int x = get(g[v][i].s, g[u][i].s);
        if (x != 0)
            return x;
    }
    return 0;
}

bool cmp(int v, int u) {
    return get(v, u) == -1;
}

void dfs(int v) {
    t[v].pb(v);
    for (auto it: g[v]) {
        int to = it.s;
        dfs(to);
        for (auto x: t[to])
            t[v].pb(x);
    }
    sort(t[v].begin() + 1, t[v].end(), cmp);

    bool ok = 1;
    ok &= (t[v][0] == v);
    for (int i = 1; i < t[v].size(); i++) {
        int cnt = 0;
        for (int j = 1; j < i; j++)
            if (C[t[v][i]] == C[t[v][j]])
                cnt++;
        ok &= (t[v][cnt] == P[t[v][i]]);
    }
    ans[v] |= ok;

}

vector<int> beechtree(int N, int M, vector<int> PP, vector<int> CC) {

    n = N;
    for (int i = 0; i < n; i++) {
        g[i].clear();
        t[i].clear();
        P[i] = PP[i];
        C[i] = CC[i];
        ans[i] = 0;
    }
    for (int i = 1; i < n; i++)
        g[P[i]].pb({C[i], i});
    for (int i = 0; i < n; i++)
        sort(g[i].begin(), g[i].end());

    dfs(0);


    return vector<int>(ans, ans + n);
}

Compilation message

beechtree.cpp: In function 'int get(int, int)':
beechtree.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i = 0; i < g[v].size(); i++) {
      |                     ~~^~~~~~~~~~~~~
beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 1; i < t[v].size(); i++) {
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 3 ms 18008 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 3 ms 18012 KB Output is correct
3 Correct 3 ms 18008 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18052 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 3 ms 18012 KB Output is correct
13 Correct 5 ms 18056 KB Output is correct
14 Correct 3 ms 18012 KB Output is correct
15 Correct 3 ms 18012 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 3 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 3 ms 18012 KB Output is correct
20 Correct 4 ms 18012 KB Output is correct
21 Correct 4 ms 18012 KB Output is correct
22 Correct 4 ms 18012 KB Output is correct
23 Correct 3 ms 18012 KB Output is correct
24 Correct 4 ms 18012 KB Output is correct
25 Correct 4 ms 18212 KB Output is correct
26 Correct 4 ms 18012 KB Output is correct
27 Correct 4 ms 18012 KB Output is correct
28 Incorrect 4 ms 18264 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 3 ms 18012 KB Output is correct
3 Correct 3 ms 18008 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Execution timed out 2009 ms 54004 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18008 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 3 ms 18012 KB Output is correct
9 Incorrect 4 ms 18012 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 4 ms 18012 KB Output is correct
2 Correct 3 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Execution timed out 2009 ms 54004 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 3 ms 18008 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 3 ms 18012 KB Output is correct
6 Correct 3 ms 18008 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18052 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 3 ms 18012 KB Output is correct
16 Correct 5 ms 18056 KB Output is correct
17 Correct 3 ms 18012 KB Output is correct
18 Correct 3 ms 18012 KB Output is correct
19 Correct 4 ms 18012 KB Output is correct
20 Correct 3 ms 18012 KB Output is correct
21 Correct 4 ms 18012 KB Output is correct
22 Correct 3 ms 18012 KB Output is correct
23 Correct 4 ms 18012 KB Output is correct
24 Correct 4 ms 18012 KB Output is correct
25 Correct 4 ms 18012 KB Output is correct
26 Correct 3 ms 18012 KB Output is correct
27 Correct 4 ms 18012 KB Output is correct
28 Correct 4 ms 18212 KB Output is correct
29 Correct 4 ms 18012 KB Output is correct
30 Correct 4 ms 18012 KB Output is correct
31 Incorrect 4 ms 18264 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 3 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18052 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 3 ms 18012 KB Output is correct
9 Correct 5 ms 18056 KB Output is correct
10 Correct 3 ms 18012 KB Output is correct
11 Correct 3 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 3 ms 18012 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 3 ms 18012 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 3 ms 18012 KB Output is correct
20 Correct 4 ms 18012 KB Output is correct
21 Correct 4 ms 18212 KB Output is correct
22 Correct 4 ms 18012 KB Output is correct
23 Correct 4 ms 18012 KB Output is correct
24 Incorrect 4 ms 18264 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 3 ms 18008 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 3 ms 18012 KB Output is correct
6 Correct 3 ms 18008 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18052 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 3 ms 18012 KB Output is correct
16 Correct 5 ms 18056 KB Output is correct
17 Correct 3 ms 18012 KB Output is correct
18 Correct 3 ms 18012 KB Output is correct
19 Correct 4 ms 18012 KB Output is correct
20 Correct 3 ms 18012 KB Output is correct
21 Correct 4 ms 18012 KB Output is correct
22 Correct 3 ms 18012 KB Output is correct
23 Correct 4 ms 18012 KB Output is correct
24 Correct 4 ms 18012 KB Output is correct
25 Correct 4 ms 18012 KB Output is correct
26 Correct 3 ms 18012 KB Output is correct
27 Correct 4 ms 18012 KB Output is correct
28 Correct 4 ms 18212 KB Output is correct
29 Correct 4 ms 18012 KB Output is correct
30 Correct 4 ms 18012 KB Output is correct
31 Incorrect 4 ms 18264 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 3 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 4 ms 18052 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 3 ms 18012 KB Output is correct
9 Correct 5 ms 18056 KB Output is correct
10 Correct 3 ms 18012 KB Output is correct
11 Correct 3 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 3 ms 18012 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 3 ms 18012 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 3 ms 18012 KB Output is correct
20 Correct 4 ms 18012 KB Output is correct
21 Correct 4 ms 18212 KB Output is correct
22 Correct 4 ms 18012 KB Output is correct
23 Correct 4 ms 18012 KB Output is correct
24 Incorrect 4 ms 18264 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 3 ms 18008 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 3 ms 18012 KB Output is correct
6 Correct 3 ms 18008 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18052 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 3 ms 18012 KB Output is correct
16 Correct 5 ms 18056 KB Output is correct
17 Correct 3 ms 18012 KB Output is correct
18 Correct 3 ms 18012 KB Output is correct
19 Correct 4 ms 18012 KB Output is correct
20 Correct 3 ms 18012 KB Output is correct
21 Correct 4 ms 18012 KB Output is correct
22 Correct 3 ms 18012 KB Output is correct
23 Correct 4 ms 18012 KB Output is correct
24 Correct 4 ms 18012 KB Output is correct
25 Correct 4 ms 18012 KB Output is correct
26 Correct 3 ms 18012 KB Output is correct
27 Correct 4 ms 18012 KB Output is correct
28 Correct 4 ms 18212 KB Output is correct
29 Correct 4 ms 18012 KB Output is correct
30 Correct 4 ms 18012 KB Output is correct
31 Incorrect 4 ms 18264 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
32 Halted 0 ms 0 KB -