[Solution] Jatayu's Balanced Bracket Sequence Codeforces Solution
Last summer, Feluda gifted Lalmohan-Babu a balanced bracket sequence of length .
Topshe was bored during his summer vacations, and hence he decided to draw an undirected graph of vertices using the balanced bracket sequence . For any two distinct vertices and (), Topshe draws an edge (undirected and unweighted) between these two nodes if and only if the subsegment forms a balanced bracket sequence.
Determine the number of connected components in Topshe's graph.
See the Notes section for definitions of the underlined terms.
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer () — the number of opening brackets in string .
The second line of each test case contains a string of length — a balanced bracket sequence consisting of opening brackets "(", and closing brackets ")".
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the number of connected components in Topshe's graph.
No comments:
Post a Comment