問題一覧 > 通常問題

No.1914 Directed by Two Sequences

レベル : / AI推定難易度 : 2900 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 7
作問者 : chineristAC / テスター : tokusakurai HYEA LEE
お気に入りにしたユーザー ProblemId : 7227 / 自分の提出
問題文最終更新日: 2022-05-13 23:38:26
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 340 (順位表) の他の問題:

Problem Statement

You are given integer sequences $A=(A_1,\ A_2,\ \dots,\ A_N),\ B=(B_1,\ B_2,\ \dots,\ B_N)$ of length $N$, and $M$ pairs of $2$ vertices $(u_i,\ v_i)\ (1\le i \le M)$.

There is a directed graph $G$ with $N$ vertices and $\frac{N(N-1)}{2}-M$ edges. Regarding the directed edge between $2$ vertices $x,\ y\ (1\le x < y \le N)$, the following holds:

  • If there exists an integer $i\ (1\le i \le M)$ such that $(x,\ y)=(u_i,\ v_i)$:
  • There is no directed edge between vertices $x,\ y$.

  • Otherwise:
  • If $A_x < B_y$, there is a directed edge from vertex $x$ to vertex $y$; otherwise, there is a directed edge from vertex $y$ to vertex $x$.

Find $1$ simple directed graph $G'$ satisfying the following conditions. It can be proved that at least $1$ such $G'$ exists under the constraints of this problem.

Conditions

  • The number of vertices is $N$, and the number of edges is at most $3 \times 10^5$.
  • "There is a path from vertex $x$ to vertex $y$ in graph $G$ $\iff$ there is a path from vertex $x$ to vertex $y$ in graph $G'$" holds.

Input

$N$ $M$
$A_1$ $A_2$ $\dots$ $A_N$
$B_1$ $B_2$ $\dots$ $B_N$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_M$ $v_M$
  • $1 \le N \le 5 \times 10^4$
  • $0 \le M \le \min(\frac{N(N-1)}{2},10^5)$
  • $1 \le A_i,B_i \le 2N$
  • If $i \neq j$, then $A_i \neq A_j,\ B_i \neq B_j$
  • $A_i \neq B_j\ (1\le i,\ j \le N)$
  • $1 \le u_i < v_i \le N$
  • If $i \neq j$, then $(u_i,\ v_i) \neq (u_j,\ v_j)$
  • All input values are integers.

Output

Let $M'$ be the number of edges of $G'$, and let the $i$-th edge be directed from vertex $u'_i$ to vertex $v'_i$. Output in the following format.

$M'$
$u'_1$ $v'_1$
$u'_2$ $v'_2$
$\vdots$
$u'_{M'}$ $v'_{M'}$

In addition to the conditions of the problem, the output must satisfy the following conditions.

  • $0 \le M' \le 3 \times 10^5$
  • $1 \le u'_i,\ v'_i \le N$
  • If $i \neq j$, then $(u'_i,\ v'_i) \neq (u'_j,\ v'_j)$

If there are multiple graphs satisfying the conditions, you may output any of them.

Print a newline at the end.

Sample

Sample 1
Input
4 1
7 3 1 5
4 2 8 6
1 2
Output
4
1 3
2 3
3 4
4 1

Denoting an edge from vertex $x$ to vertex $y$ by $(x,\ y)$, graph $G$ has the $5$ edges $(1,\ 3),\ (4,\ 1),\ (2,\ 3),\ (2,\ 4),\ (3,\ 4)$.

From vertex $1$, there are paths to vertices $1,\ 3,\ 4$. The same applies to vertices $3,\ 4$. From vertex $2$, there are paths to vertices $1,\ 2,\ 3,\ 4$.

Graph $G'$ is obtained by removing edge $(2,\ 4)$ from graph $G$, and the existence of a path between any $2$ vertices does not change.

Sample 2
Input
4 6
5 1 3 7
8 2 6 4
1 2
1 3
3 4
2 3
1 4
2 4
Output
0

Graph $G$ may have no edges.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。