Codeforces Round 1040 (Div. 1)
E
Induced Subgraph Queries
Codeforces
3000
原题
← DF1 →
翻译中…

You are given an unweighted, undirected graph $G$ with $n$ nodes and $m$ edges. The graph $G$ contains no self-loops or multiple edges.

翻译中…

We denote the node set of $G$ as $V$. For any node subset $V' \subseteq V$, the corresponding induced subgraph, denoted by $G[V']$, is defined as follows:

翻译中…
  • $G[V']$ is the graph whose node set is $V'$, and whose edge set consists of all edges in $G$ with both endpoints in $V'$.
翻译中…

Your task is to answer $q$ queries. Each query provides three integers $l$, $r$, and $k$. Denoting $V'=\{l,l+1,\ldots,r\}$, you need to find the $k$-th smallest value among $f(l,G[V'])$, $f(l+1,G[V'])$, $\ldots$ , $f(r,G[V'])$ (i.e., the $k$-th value in increasing order; repeated values are counted multiple times).

翻译中…

Here, $f(u,G[V'])=\bigoplus_{(u,v)\in G[V']}v$. In other words, it is the bitwise XOR value of the labels of all adjacent nodes of node $u$ in graph $G[V']$.

翻译中…

You might want to read the notes for a better understanding.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1.5 \cdot 10^4$). The description of the test cases follows.

翻译中…

Each test case begins with two integers $n$ and $m$ ($2 \leq n \leq 1.5 \cdot 10^5$, $1 \leq m \leq 1.5 \cdot 10^5$) — the number of nodes and edges, respectively.

翻译中…

The next $m$ lines each contain two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$), representing an undirected edge between nodes $u_i$ and $v_i$.

翻译中…

The next line contains a single integer $q$ ($1 \leq q \leq 1.5 \cdot 10^5$) — the number of queries.

翻译中…

Each of the next $q$ lines contains three integers $l$, $r$, and $k$ ($1 \leq l \leq r \leq n$, $1 \le k \le r-l+1$), defining a query about the induced subgraph $G[\{l,\ldots,r\}]$.

翻译中…

It is guaranteed that the graph contains no self-loops or multiple edges.

翻译中…

It is guaranteed that the sum of $n$,$m$, and $q$ over all test cases does not exceed $1.5 \cdot 10^5$, respectively.

翻译中…

Output

翻译中…

For each test case, output $q$ integers, representing the answer for each query.

翻译中…

Note

翻译中…

In the first test case, the input graph $G$ is the one in the following picture.

翻译中…

image The given graph $G$.

翻译中…

In the first query, the induced subgraph $G[\{1,2\}]$ is the one in the following picture. We can see that nodes $1$ and $2$ have no adjacent nodes. Thus, $f(1,G[\{1,2\}])=f(2,G[\{1,2\}])=0$. The $2$-nd smallest value is $0$.

翻译中…

image $G[\{1,2\}]$.

翻译中…

In the second query, the induced subgraph $G[\{1,2,3\}]$ is the one in the following picture. We can see that $f(1,G[\{1,2,3\}])=3$, $f(2,G[\{1,2,3\}])=3$, and $f(3,G[\{1,2,3\}])=1 \oplus 2=3$. The $1$-st smallest value is $3$.

翻译中…

image $G[\{1,2,3\}]$.

翻译中…

In the third query, the induced subgraph $G[\{2,3,4\}]$ is the one in the following picture. We can see that $f(2,G[\{2,3,4\}])=3 \oplus 4=7$, $f(3,G[\{2,3,4\}])=2 \oplus 4=6$, and $f(4,G[\{2,3,4\}])=2 \oplus 3=1$. The $3$-rd smallest value is $7$.

翻译中…

image $G[\{2,3,4\}]$.

翻译中…

样例

Input #1
2
4 5
1 3
1 4
2 3
2 4
3 4
3
1 2 2
1 3 1
2 4 3
2 1
2 1
3
1 1 1
2 2 1
1 2 2
Output #1
0
3
7
0
0
2
InputCopy OutputCopy
题目信息
题号
2129E
时间限制
5 s
内存限制
512 MB
标签
数据结构
图论
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。