#P10572. [JRKSJ R8] +1-1

    ID: 11005 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2024洛谷原创O2优化二分图洛谷月赛

[JRKSJ R8] +1-1

Problem Description

You are given an undirected graph with nn vertices and mm edges. Each vertex has a character ( or ) on it.

There are qq queries. Each query gives x,yx, y, and you need to determine whether there exists a path from xx to yy (it does not have to be a simple path) such that, if you write down the characters on the vertices along the path in order, the resulting string is a valid bracket sequence.

Input Format

The first line contains three integers n,m,qn, m, q.

The second line contains a string of length nn consisting only of ( and ), representing the characters on vertices 1n1 \dots n.

The next mm lines each contain two integers u,vu, v, denoting an edge in the graph.

The next qq lines each contain two integers x,yx, y.

Output Format

Output a 01 string of length qq. The ii-th character represents the answer to the ii-th query: output 1 if such a path exists, otherwise output 0.

5 6 5
((())
1 2
1 3
2 3
3 4
4 5
2 4

1 2
3 4
1 4
1 5
2 5

01111

Hint

Definition of a valid bracket sequence:

  • The empty string is a valid bracket sequence.
  • If A,BA, B are valid bracket sequences, then ABAB is a valid bracket sequence.
  • If AA is a valid bracket sequence, then (A)(A) is a valid bracket sequence.
  • Any other string is not a valid bracket sequence.

For example, () and (()()) are valid bracket sequences, while (() and ())( are not.

Sample Explanation

To make it easier to read, there is a blank line between the edges and the queries in the sample input. However, this blank line does not exist in the actual testdata.

Vertices 1,2,31, 2, 3 have character (, and vertices 4,54, 5 have character ).

121\to 2: Obviously, a valid bracket sequence cannot end with (.
343\to 4: The string represented by the path 343\to 4 is ().
141\to 4: The string represented by the path 1324541\to 3\to 2\to 4\to 5\to 4 is ((())).
151\to 5: The string represented by the path 12451\to 2\to 4\to 5 is (()).
252\to 5: The string represented by the path 23452\to 3\to 4\to 5 is (()).

Constraints

This problem uses bundled testdata.

  • Subtask 1 (20 pts): n,q500n, q \le 500, m800m \le 800.
  • Subtask 2 (30 pts): The graph is a forest.
  • Subtask 3 (20 pts): q10q \le 10.
  • Subtask 4 (30 pts): No special restrictions.

For all testdata, 1n,q5×1051 \le n, q \le 5\times 10^5, $0 \le m \le \min(\frac{n\times(n-1)}{2}, 5\times 10^5)$, 1u,v,x,yn1 \le u, v, x, y \le n. The given graph is guaranteed to have no multiple edges and no self-loops.

Translated by ChatGPT 5