<p>Given a balanced parentheses string <code>s</code>, return <em>the <strong>score</strong> of the string</em>.</p>

<p>The <strong>score</strong> of a balanced parentheses string is based on the following rule:</p>

<ul>
	<li><code>&quot;()&quot;</code> has score <code>1</code>.</li>
	<li><code>AB</code> has score <code>A + B</code>, where <code>A</code> and <code>B</code> are balanced parentheses strings.</li>
	<li><code>(A)</code> has score <code>2 * A</code>, where <code>A</code> is a balanced parentheses string.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;()&quot;
<strong>Output:</strong> 1
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;(())&quot;
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;()()&quot;
<strong>Output:</strong> 2
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= s.length &lt;= 50</code></li>
	<li><code>s</code> consists of only <code>&#39;(&#39;</code> and <code>&#39;)&#39;</code>.</li>
	<li><code>s</code> is a balanced parentheses string.</li>
</ul>

class Solution {
public:
    int solve(vector<vector<int>> &g, int sr, vector<int> &vis){
        vis[sr]=1;
        int count=0;
        for(auto ch: g[sr]){
            if(vis[ch]) continue;
            count+=solve(g, ch, vis);
        }
        if(count==0) return 1;
        else return 2*count;
    }
    int scoreOfParentheses(string s) {
        int n=s.size();
        vector<vector<int>> g(n);
        stack<int> st;
        set<int> x;
        for(int i=0; i<n; ++i){
            if(s[i]=='('){
                if(!st.empty()){
                auto it=st.top();
                g[it].push_back(i);}
                st.push(i);
                x.insert(i);
            }
            else{
                st.pop();
            }
        }
        for(auto val: x){
            cout<<val<<" ";
        }
        int ans=0;
        vector<int> vis(n, 0);
        for(auto val: x){
            if(vis[val]) continue;
            ans+=solve(g, val, vis);
        }
        return ans;
    }
};
8100