update
This commit is contained in:
parent
dd20cc9fd8
commit
2d3a3ce03b
38
src/P5658/P5658.cpp
Normal file
38
src/P5658/P5658.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using ll = long long;
|
||||
|
||||
const ll max_n = 5e5;
|
||||
ll n, father;
|
||||
std::string s;
|
||||
std::vector<ll> son[max_n];
|
||||
char c[max_n];
|
||||
|
||||
void dfs(const ll now, const std::stack<char> &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<char> first_parenthesis;
|
||||
first_parenthesis.push(c[1]);
|
||||
dfs(1, first_parenthesis);
|
||||
}
|
Loading…
Reference in New Issue
Block a user