# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061289 | 2024-08-16T07:44:06 Z | tolbi | Beech Tree (IOI23_beechtree) | C++17 | 1 ms | 348 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); } cout<<arr[1].size()<<endl; 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 | Incorrect | 0 ms | 348 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Possible tampering with the output |
2 | Halted | 0 ms | 0 KB | - |