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