# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061291 | 2024-08-16T07:44:28 Z | tolbi | Beech Tree (IOI23_beechtree) | C++17 | 125 ms | 105164 KB |
#include "beechtree.h" #include <bits/stdc++.h> using namespace std; bool valid(vector<vector<int>> &arr){ vector<int> in(arr.size()); for (int i = 0; i < arr.size(); i++){ for (auto it : arr[i]){ in[it]++; } } queue<int> q; int say = 0; for (int i = 0; i < arr.size(); i++){ if (in[i]==0) q.push(i); } while (q.size()){ int node = q.front(); say++; q.pop(); for (auto it : arr[node]){ in[it]--; if (in[it]==0) q.push(it); } } return (say==arr.size()); } std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C) { vector<int> ans(N); vector<vector<int>> arr(N); for (int i = 1; i < N; i++){ arr[P[i]].push_back(i); } vector<set<int>> v(N); function<void(int)> dfs = [&](int node)->void{ bool boolean=true; map<int,vector<int>> mp; map<int,int> vv; int ind = 0; for (auto it : arr[node]){ dfs(it); if (ans[it]==0){ boolean=false; } if (boolean){ for (auto it2 : v[it]){ mp[it2].push_back(ind); } vv[C[it]]=ind; ind++; } } if (vv.size()!=arr[node].size()){ boolean=false; } if (boolean){ vector<vector<int>> gr(arr[node].size()); for (auto it : mp){ int hh = vv[it.first]; for (auto it2 : it.second){ if (hh==it2) continue; gr[hh].push_back(it2); } } if (!valid(gr)){ boolean=false; } } if (boolean){ for (auto it : mp){ v[node].insert(it.first); } for (auto it : arr[node]){ v[node].insert(C[it]); } if (v[node].size()!=arr[node].size()){ boolean=false; while (v[node].size()) v[node].erase(v[node].begin()); return; } ans[node]=1; } }; dfs(0); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 436 KB | Output is correct |
# | 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 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Incorrect | 1 ms | 348 KB | 2nd lines differ - on the 1st token, expected: '0', found: '1' |
10 | 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 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 100 ms | 95920 KB | Output is correct |
8 | Correct | 96 ms | 96072 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 1372 KB | Output is correct |
14 | Correct | 2 ms | 1372 KB | Output is correct |
15 | Correct | 1 ms | 1372 KB | Output is correct |
16 | Correct | 1 ms | 1372 KB | Output is correct |
17 | Correct | 125 ms | 105164 KB | Output is correct |
18 | Correct | 117 ms | 101976 KB | Output is correct |
19 | Correct | 101 ms | 97616 KB | Output is correct |
20 | Correct | 93 ms | 95920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Incorrect | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 100 ms | 95920 KB | Output is correct |
6 | Correct | 96 ms | 96072 KB | Output is correct |
7 | Incorrect | 0 ms | 348 KB | 2nd lines differ - on the 74th token, expected: '0', found: '1' |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 436 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Incorrect | 1 ms | 348 KB | 2nd lines differ - on the 1st token, expected: '0', found: '1' |
13 | 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 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 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 | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 436 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Incorrect | 1 ms | 348 KB | 2nd lines differ - on the 1st token, expected: '0', found: '1' |
13 | 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 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 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 | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 436 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Incorrect | 1 ms | 348 KB | 2nd lines differ - on the 1st token, expected: '0', found: '1' |
13 | Halted | 0 ms | 0 KB | - |