From 2d3a3ce03b6f3e3707f2595ac9c0ddf4f8a3383a Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Thu, 24 Oct 2024 09:27:07 +0800 Subject: [PATCH] update --- src/P5658/P5658.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/P5658/P5658.cpp diff --git a/src/P5658/P5658.cpp b/src/P5658/P5658.cpp new file mode 100644 index 0000000..0706b88 --- /dev/null +++ b/src/P5658/P5658.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +using ll = long long; + +const ll max_n = 5e5; +ll n, father; +std::string s; +std::vector son[max_n]; +char c[max_n]; + +void dfs(const ll now, const std::stack &parenthesis){ + + + for(const auto i:son[now]){ + auto new_parenthesis = parenthesis; + new_parenthesis.push(c[i]); + dfs(i, new_parenthesis); + } +} + +int main(){ + std::cin>>n; + std::cin>>s; + for(ll i{1};i<=n;i++){ + c[i]=s[i-1]; + } + for(ll i{2};i<=n;i++){ + std::cin>>father; + son[father].push_back(i); + } + + std::stack first_parenthesis; + first_parenthesis.push(c[1]); + dfs(1, first_parenthesis); +} \ No newline at end of file