No.2290 UnUnion Find
問題文最終更新日: 2023-05-12 01:57:05
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
Problem Statement
You are given a graph $G$ with $N$ vertices and $0$ edges. The vertices are numbered from $1$ to $N$.
$Q$ queries of the following forms are given, so process them in order on the graph $G$.
1 u v: Connect vertex $u$ and vertex $v$ with an edge.2 v: Output one vertex that is not connected to vertex $v$. If no such vertex exists, output-1.
Input
$N\ \ Q$
${\rm Query}_{1}$
${\rm Query}_{2}$
${\rm Query}_{3}$
$\ \ \ \ \vdots$
${\rm Query}_{i}$
$\ \ \ \ \vdots$
${\rm Query}_{Q}$
- $1\leq N \leq 2\times 10^{5}$
- $1\leq Q \leq 2\times 10^{5}$
- For ${\rm Query}_{i}$:
For a type 1 query$1\ u_{i}\ v_{i}$For a type 2 query$2\ \ v_{i}$・$1 \leq u_{i}, v_{i} \leq N$ - All inputs are integers.
Output
If $K$ type 2 queries are given, output the answer to the $i$-th type 2 query on line $i\ (1 \leq i \leq K) $. If there are multiple solutions, any of them will be accepted. Print a newline at the end.
Sample
Sample 1
Input
4 7 2 1 1 1 2 2 1 1 3 4 2 4 1 1 3 2 1
Output
2 3 1 -1
- The 1st query asks for a vertex not connected to vertex $1$. Output any of $2$ , $3$ , $4$ , which are the vertices not connected to vertex $1$.
- In the 2nd query, vertex $1$ and vertex $2$ are connected with an edge.
- The 3rd query asks for a vertex not connected to vertex $1$. Output any of $3$ , $4$ , which are the vertices not connected to vertex $1$.
- In the 4th query, vertex $3$ and vertex $4$ are connected with an edge.
- The 5th query asks for a vertex not connected to vertex $4$. Output any of $1$ , $2$ , which are the vertices not connected to vertex $4$.
- In the 6th query, vertex $1$ and vertex $3$ are connected with an edge.
- The 7th query asks for a vertex not connected to vertex $1$. Since no vertex is disconnected from vertex $1$, output $-1$ .
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。