#abc260f. F - Find 4-cycle

F - Find 4-cycle

Score : 500500 points

问题描述

我们有一个简单的无向图 GG,包含 (S+T)(S+T) 个顶点和 MM 条边。顶点编号从 11(S+T)(S+T),边编号从 11MM。第 ii 条边连接顶点 uiu_iviv_i

这里,顶点集合 V1={1,2,,S}V_1 = \lbrace 1, 2,\dots, S\rbraceV2={S+1,S+2,,S+T}V_2 = \lbrace S+1, S+2, \dots, S+T \rbrace 都是独立集。

长度为 44 的环称为 4-环。
如果 GG 中包含一个 4-环,请任意选择其中一个,并按照任意顺序打印该环中的顶点。
如果 GG 不包含 4-环,则打印 -1

什么是独立集?在图 GG 中,独立集 VV'GG 中一些顶点的集合,其中任意两个顶点之间都没有边相连。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a simple undirected graph GG with (S+T)(S+T) vertices and MM edges. The vertices are numbered 11 through (S+T)(S+T), and the edges are numbered 11 through MM. Edge ii connects Vertices uiu_i and viv_i.
Here, vertex sets V1={1,2,,S}V_1 = \lbrace 1, 2,\dots, S\rbrace and V2={S+1,S+2,,S+T}V_2 = \lbrace S+1, S+2, \dots, S+T \rbrace are both independent sets.

A cycle of length 44 is called a 4-cycle.
If GG contains a 4-cycle, choose any of them and print the vertices in the cycle. You may print the vertices in any order.
If GG does not contain a 4-cycle, print -1.

What is an independent set? An independent set of a graph GG is a set VV' of some of the vertices in GG such that no two vertices of VV' have an edge between them.

Constraints

  • 2S3×1052 \leq S \leq 3 \times 10^5
  • 2T30002 \leq T \leq 3000
  • 4Mmin(S×T,3×105)4 \leq M \leq \min(S \times T,3 \times 10^5)
  • 1uiS1 \leq u_i \leq S
  • S+1viS+TS + 1 \leq v_i \leq S + T
  • If iji \neq j, then (ui,vi)(uj,vj)(u_i, v_i) \neq (u_j, v_j).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

SS TT MM

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uMu_M vMv_M

Output

If GG contains a 4-cycle, choose any of them, and print the indices of the four distinct vertices in the cycle. (The order of the vertices does not matter.)
If GG does not contain a 4-cycle, print -1.

Sample Input 1

2 3 5
1 3
1 4
1 5
2 4
2 5

Sample Output 1

1 2 4 5

There are edges between Vertices 11 and 44, 44 and 22, 22 and 55, and 55 and 11, so Vertices 11, 22, 44, and 55 form a 4-cycle. Thus, 11, 22, 44, and 55 should be printed.
The vertices may be printed in any order. Besides the Sample Output, 2 5 1 4 is also considered correct, for example.

Sample Input 2

3 2 4
1 4
1 5
2 5
3 5

Sample Output 2

-1

Some inputs may give GG without a 4-cycle.

Sample Input 3

4 5 9
3 5
1 8
3 7
1 9
4 6
2 7
4 8
1 7
2 9

Sample Output 3

1 7 2 9

update @ 2024/3/10 11:02:14