A - Big Clique Everywhere

実行時間制限: 4 sec / メモリ制限: 1024 MiB

配点 : 600

問題文

1 から N までの番号がついた N 頂点の単純無向グラフ G が与えられます。 GM 本の辺を持ち、i 本目の辺は頂点 A_iB_i を結びます。

G が次の条件を満たすか判定してください。

  • 頂点集合 \{1,2,\cdots,N\} のすべての部分集合 X に対して、X の部分集合 Y であって |Y|\ge \frac{|X|}{2} かつ Y がクリークを形成するものが存在する。

解くべきテストケースは T 個あります。

制約

  • 1\le T \le 10^3
  • 1\le N \le 10^5
  • 0 \le M \le 10^6
  • 1 \le A_i,B_i \le N
  • 与えられるグラフは自己辺も多重辺も含まない。
  • ひとつの入力の中のテストケースすべてにわたる N の総和は 10^5 以下である。
  • ひとつの入力の中のテストケースすべてにわたる M の総和は 10^6 以下である。
  • すべての入力値は整数である。

入力

入力は標準入力から以下の形式で与えられる。

T
case_1
case_2
\vdots
case_T

各テストケースは以下の形式で与えられる。

N M
A_1 B_1
A_2 B_2
\vdots
A_M B_M

出力

各テストケースについて、G が条件を満たすなら Yes、そうでないなら No と出力せよ。
Yes または No の出力において、各文字は大文字・小文字のいずれでもよい。


入力例 1

4
3 3
1 2
1 3
2 3
3 2
1 2
1 3
3 1
1 2
3 0

出力例 1

Yes
Yes
Yes
No

1 番目のテストケースについて、G は条件を満たします。 この場合、すべての部分集合 X がクリークであるため、単に Y=X とできます。

2 番目のテストケースについて、G は条件を満たします。 例えば、X=\{2,3\} に対しては、Y=\{2\} とできます。

4 番目のテストケースについて、G は条件を満たしません。 X=\{1,2,3\} とすると、条件を満たす X の部分集合 Y はありません。

Score : 600 points

Problem Statement

You are given a simple undirected graph G with N vertices numbered 1 to N. G has M edges and the i-th edge connects vertices A_i and B_i.

Check if G satisfies the following condition:

  • For every subset X of the vertex set \{1,2,\cdots,N\}, there exists a subset Y of X such that |Y|\ge \frac{|X|}{2} and Y forms a clique.

You have T testcases to solve.

Constraints

  • 1\le T \le 10^3
  • 1\le N \le 10^5
  • 0 \le M \le 10^6
  • 1 \le A_i,B_i \le N
  • The given graph doesn't contain self-loops or multiple edges.
  • The sum of N across the test cases in a single input is at most 10^5.
  • The sum of M across the test cases in a single input is at most 10^6.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

T
case_1
case_2
\vdots
case_T

Each test case is given in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_M B_M

Output

For each test case, if G satisfies the condition, print Yes, and otherwise print No.
In printing Yes or No, you can output each letter in any case (upper or lower).


Sample Input 1

4
3 3
1 2
1 3
2 3
3 2
1 2
1 3
3 1
1 2
3 0

Sample Output 1

Yes
Yes
Yes
No

For the 1-st test case, G satisfies the condition. In this case, every subset X is a clique, so we can just let Y=X.

For the 2-nd test case, G satisfies the condition. For example, for X=\{2,3\}, we can let Y=\{2\}.

For the 4-th test case, G doesn't satisfy the condition. If we let X=\{1,2,3\}, no subset Y of X satisfies the condition.

B - Modifications

実行時間制限: 3 sec / メモリ制限: 1024 MiB

配点 : 1100

問題文

長さ N の整数列 a=(a_1,a_2,\cdots,a_N) があります。 すべての要素ははじめ 0 です。

整数 CM 個の区間 ([L_1,R_1],[L_2,R_2],\cdots,[L_M,R_M]) が与えられます。

あなたは、(1,2,\cdots,M) の順列 p と長さ M の整数列 w=(w_1,w_2,\cdots,w_M) を選びます。 ここで、1\le w_i\le C でなければなりません。

そして、M 回の変更を行います。 i 回目の変更は以下です。

  • a_{L_{p_i}}, \cdots, a_{R_{p_i}}w_i に変える。

a の中のすべての位置が少なくとも一つの区間に覆われることが保証されます。

すべての変更後の a としてありうるものの個数を求め、答えを 998244353 で割った余りを出力してください。

制約

  • 1\le N\le 100
  • 1\le M\le\dfrac{N(N+1)}{2}
  • 1\le C<998244353
  • 1 \le L_i \le R_i \le N
  • (L_i,R_i) \neq (L_j,R_j) (i \neq j)
  • a の中のすべての位置は少なくとも一つの区間に覆われる。
  • すべての入力値は整数である。

入力

入力は標準入力から以下の形式で与えられる。

N M C
L_1 R_1
L_2 R_2
\vdots
L_M R_M

出力

答えを出力せよ。


入力例 1

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

出力例 1

16

ありうる数列は 16 個あります。 例えば、a=(2,1,1,1,1) は以下のようにして得られます。

  • p=(4,1,2,3,5)w=(1,2,1,2,1) を選ぶ
  • 1 回目の操作で a(1,1,1,1,1) になる
  • 2 回目の操作で a(2,2,2,1,1) になる
  • 3 回目の操作で a(2,1,2,1,1) になる
  • 4 回目の操作で a(2,1,2,1,1) になる
  • 5 回目の操作で a(2,1,1,1,1) になる

入力例 2

20 30 20
1 14
1 7
1 16
3 13
1 17
4 8
2 11
4 12
9 14
3 15
11 19
1 13
4 15
8 19
3 17
15 18
10 18
1 18
17 19
16 20
1 8
8 15
13 17
1 19
13 19
1 20
6 13
10 12
11 20
17 18

出力例 2

258066445

Score : 1100 points

Problem Statement

You have an integer sequence a=(a_1,a_2,\cdots,a_N) of length N. All elements are initially 0.

You are given an integer C and M intervals ([L_1,R_1],[L_2,R_2],\cdots,[L_M,R_M]).

You will choose a permutation p of (1,2,\cdots,M) and an integer sequence w=(w_1,w_2,\cdots,w_M) of length M. Here, 1\le w_i\le C must hold.

Then, you will do M modifications. The i-th modification is the following:

  • Change a_{L_{p_i}}, \cdots, a_{R_{p_i}} to w_i.

It is guaranteed that every position in a is covered by at least one interval.

Find the number of achievable a after all modifications. Print the answer modulo 998244353.

Constraints

  • 1\le N\le 100
  • 1\le M\le\dfrac{N(N+1)}{2}
  • 1\le C<998244353
  • 1 \le L_i \le R_i \le N
  • (L_i,R_i) \neq (L_j,R_j) (i \neq j)
  • Every position in a is covered by at least one interval.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N M C
L_1 R_1
L_2 R_2
\vdots
L_M R_M

Output

Print the answer.


Sample Input 1

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

Sample Output 1

16

There are 16 sequences that can be achieved. For example, you can achieve a=(2,1,1,1,1) in the following manner:

  • Choose p=(4,1,2,3,5) and w=(1,2,1,2,1)
  • The 1-st operation changes a into (1,1,1,1,1)
  • The 2-nd operation changes a into (2,2,2,1,1)
  • The 3-rd operation changes a into (2,1,2,1,1)
  • The 4-th operation changes a into (2,1,2,1,1)
  • The 5-th operation changes a into (2,1,1,1,1)

Sample Input 2

20 30 20
1 14
1 7
1 16
3 13
1 17
4 8
2 11
4 12
9 14
3 15
11 19
1 13
4 15
8 19
3 17
15 18
10 18
1 18
17 19
16 20
1 8
8 15
13 17
1 19
13 19
1 20
6 13
10 12
11 20
17 18

Sample Output 2

258066445
C - Divisibility Homomorphism

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 1100

問題文

正整数の無限列 (a_1,a_2,\cdots) が以下の条件をともに満たすとき、またそのときに限りそれを 良い と呼びます。

  • ある有限の定数 C が存在し、すべての 1 \le n について a_n \le C \cdot n である。
  • すべての正整数の組 (n,m) に対し、a_n \mid a_mn\mid m とは同値である。ここで、x \mid yxy を割り切ることを表す。

長さ N の整数列 A=(A_1,A_2,\cdots,A_N) が与えられます。 (A_1,A_2,\cdots,A_N) で始まる良い無限列が存在するか判定してください。

解くべきテストケースは T 個あります。

制約

  • 1\le T \le 5000
  • 1 \leq N \leq 5000
  • 1 \leq A_i \leq 10^{18}
  • ひとつの入力の中のテストケースすべてにわたる N の総和は 5000 以下である。
  • すべての入力値は整数である。

入力

入力は標準入力から以下の形式で与えられる。

T
case_1
case_2
\vdots
case_T

各テストケースは以下の形式で与えられる。

N
A_1 A_2 \cdots A_N

出力

各テストケースについて、(A_1,A_2,\cdots,A_N) で始まる良い無限数列が存在するなら Yes、そうでないなら No と出力せよ。
Yes または No の出力において、各文字は大文字・小文字のいずれでもよい。


入力例 1

5
5
1 2 3 4 5
5
1 4 9 16 25
5
1 4 6 8 10
5
1 2 4 4 5
5
1 2 3 5 4

出力例 1

Yes
Yes
Yes
No
No

1 番目のテストケースについて、a_n=n とでき、これは条件を満たします。

Score : 1100 points

Problem Statement

We call an infinite sequence of positive integers (a_1,a_2,\cdots) good if and only if it satisfies both of the following conditions:

  • There exists a finite constant C such that a_n \le C \cdot n for all 1 \le n;

  • For all pairs of positive integers (n,m), a_n \mid a_m if and only if n\mid m. Here, x \mid y means x divides y.

You are given a positive integer sequence A=(A_1,A_2,\cdots,A_N) of length N. Check if there exists a good infinite sequence starting with (A_1,A_2,\cdots,A_N).

You have T testcases to solve.

Constraints

  • 1\le T \le 5000
  • 1 \leq N \leq 5000
  • 1 \leq A_i \leq 10^{18}
  • The sum of N across the test cases in a single input is at most 5000.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

T
case_1
case_2
\vdots
case_T

Each test case is given in the following format:

N
A_1 A_2 \cdots A_N

Output

For each test case, if there exists a good infinite sequence starting with (A_1,A_2,\cdots,A_N), print Yes, and otherwise print No. In printing Yes or No, you can output each letter in any case (upper or lower).


Sample Input 1

5
5
1 2 3 4 5
5
1 4 9 16 25
5
1 4 6 8 10
5
1 2 4 4 5
5
1 2 3 5 4

Sample Output 1

Yes
Yes
Yes
No
No

For the 1-st test case, we can let a_n=n and that satisfies the condition.

D - Unique Matching

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 1500

問題文

整数 N と素数 P が与えられます。

以下がともに満たされるとき、またそのときに限り N 個の区間からなる列 ([L_1,R_1] ,[L_2,R_2], \cdots, [L_N,R_N])良い と呼びます。

  • すべての 1\le i\le N に対して 1\le L_i\le R_i\le N が成り立つ。
  • すべての 1\le i\le N に対して L_i\le x_i\le R_i が成り立つような (1,2,\cdots,N) の順列 x=(x_1,x_2,\cdots,x_N)ただ一つ 存在する。

良い 区間の列の個数を P で割った余りを求めてください。

制約

  • 2 \leq N \leq 5000
  • 10^9<P<1.01\times 10^9
  • P は素数である。
  • すべての入力値は整数である。

入力

入力は標準入力から以下の形式で与えられる。

N P

出力

答えを出力せよ。


入力例 1

2 1005488041

出力例 1

6

以下の 6 個が良い列です。

  • ([1,1],[2,2])
  • ([1,2],[2,2])
  • ([1,1],[1,2])
  • ([2,2],[1,1])
  • ([2,2],[1,2])
  • ([1,2],[1,1])

入力例 2

5 1005488041

出力例 2

102960

入力例 3

100 1005488041

出力例 3

47599495

入力例 4

1000 1005488041

出力例 4

632708165

Score : 1500 points

Problem Statement

You are given an integer N and prime P.

We call a sequence of N intervals ([L_1,R_1] ,[L_2,R_2], \cdots, [L_N,R_N]) good if and only if both of the followings are satisfied:

  • 1\le L_i\le R_i\le N holds for all 1\le i\le N.
  • There exists a unique permutation x=(x_1,x_2,\cdots,x_N) of (1,2,\cdots,N) such that L_i\le x_i\le R_i holds for all 1\le i\le N.

Count the number, modulo P, of good sequences of intervals.

Constraints

  • 2 \leq N \leq 5000
  • 10^9<P<1.01\times 10^9
  • P is prime.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N P

Output

Print the answer.


Sample Input 1

2 1005488041

Sample Output 1

6

The following 6 sequences are good:

  • ([1,1],[2,2])
  • ([1,2],[2,2])
  • ([1,1],[1,2])
  • ([2,2],[1,1])
  • ([2,2],[1,2])
  • ([1,2],[1,1])

Sample Input 2

5 1005488041

Sample Output 2

102960

Sample Input 3

100 1005488041

Sample Output 3

47599495

Sample Input 4

1000 1005488041

Sample Output 4

632708165
E - Biconnected Graph

実行時間制限: 3 sec / メモリ制限: 1024 MiB

配点 : 1900

問題文

整数 N と素数 P が与えられます。

1 から N までの番号がついた N 頂点の連結無向グラフであって以下の条件を満たすものの個数を P で割った余りを求めてください。

  • G に自己辺はない。なお、多重辺はあってもよい。
  • G のすべての辺 (u,v) について、(u,v)G から削除しても G は連結なままである。すなわち、G は二重辺連結である。
  • G のすべての辺 (u,v) について、(u,v)G から削除すると G は二重辺連結でなくなる。

二つのグラフは、異なる頂点の組 (u,v) であって二つのグラフで uv を結ぶ辺の本数が異なるものが存在するとき、またそのときに限り異なるとします。

制約

  • 2 \le N \le 50
  • 10^9<P<1.01\times 10^9
  • P は素数である。
  • すべての入力値は整数である。

入力

入力は標準入力から以下の形式で与えられる。

N P

出力

答えを出力せよ。


入力例 1

2 1005976817

出力例 1

1

入力例 2

5 1000837403

出力例 2

372

入力例 3

10 1001160547

出力例 3

789846604

入力例 4

20 1006779551

出力例 4

888612770

Score : 1900 points

Problem Statement

You are given an integer N and a prime P.

Count the number, modulo P, of undirected connected graphs G of N vertices numbered 1 to N that satisfy the following condition:

  • There are no self-loops in G. Note that multiple edges are allowed.
  • For all edges (u,v) in G, if we delete (u,v) from G, G remains connected. In other words, G is edge-biconnected.
  • For all edges (u,v) in G, if we delete (u,v) from G, G is no longer edge-biconnected.

Two graphs are considered different if and only if there exists a pair of distinct vertices (u,v) such that the numbers of edges connecting u and v in the two graphs are different.

Constraints

  • 2 \le N \le 50
  • 10^9<P<1.01\times 10^9
  • P is prime.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N P

Output

Print the answer.


Sample Input 1

2 1005976817

Sample Output 1

1

Sample Input 2

5 1000837403

Sample Output 2

372

Sample Input 3

10 1001160547

Sample Output 3

789846604

Sample Input 4

20 1006779551

Sample Output 4

888612770