問題一覧 > 通常問題

No.2290 UnUnion Find

レベル : / AI推定難易度 : 950 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 171
作問者 : t98slider / テスター : 👑 箱星
お気に入りにしたユーザー ProblemId : 9133 / 自分の提出
問題文最終更新日: 2023-05-12 01:57:05
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
yukicoder contest 387 (Union Find Contest) (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。