Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1 から N の番号がついており、i 番目の辺は頂点 A_i と頂点 B_i を結んでいます。 このグラフから 0 本以上のいくつかの辺を削除してグラフが閉路を持たないようにするとき、削除する辺の本数の最小値を求めてください。
単純無向グラフとは
単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。
閉路とは
単純無向グラフが閉路を持つとは、i \neq j ならば v_i \neq v_j を満たす長さ 3 以上の頂点列 (v_0, v_1, \ldots, v_{n-1}) であって、各 0 \leq i < n に対し v_i と v_{i+1 \bmod n} の間に辺が存在するものがあることをいいます。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- 与えられるグラフは単純
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
出力
答えを出力せよ。
入力例 1
6 7 1 2 1 3 2 3 4 2 6 5 4 6 4 5
出力例 1
2
頂点 1 と頂点 2 を結ぶ辺・頂点 4 と頂点 5 を結ぶ辺の 2 本を削除するなどの方法でグラフが閉路を持たないようにすることができます。
1 本以下の辺の削除でグラフが閉路を持たないようにすることはできないので、2 を出力します。
入力例 2
4 2 1 2 3 4
出力例 2
0
入力例 3
5 3 1 2 1 3 2 3
出力例 3
1
Score : 300 points
Problem Statement
You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects vertex A_i and vertex B_i. Let us delete zero or more edges to remove cycles from the graph. Find the minimum number of edges that must be deleted for this purpose.
What is a simple undirected graph?
A simple undirected graph is a graph without self-loops or multi-edges whose edges have no direction.
What is a cycle?
A cycle in a simple undirected graph is a sequence of vertices (v_0, v_1, \ldots, v_{n-1}) of length at least 3 satisfying v_i \neq v_j if i \neq j such that for each 0 \leq i < n, there is an edge between v_i and v_{i+1 \bmod n}.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- The given graph is simple.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
Output
Print the answer.
Sample Input 1
6 7 1 2 1 3 2 3 4 2 6 5 4 6 4 5
Sample Output 1
2
One way to remove cycles from the graph is to delete the two edges between vertex 1 and vertex 2 and between vertex 4 and vertex 5.
There is no way to remove cycles from the graph by deleting one or fewer edges, so you should print 2.
Sample Input 2
4 2 1 2 3 4
Sample Output 2
0
Sample Input 3
5 3 1 2 1 3 2 3
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
整数 N が与えられるので、以下の問題を解いてください。
f(x)= ( x 以下の正整数で、 x と桁数が同じものの数) とします。
f(1)+f(2)+\dots+f(N) を 998244353 で割った余りを求めてください。
制約
- N は整数
- 1 \le N < 10^{18}
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
16
出力例 1
73
- 1 以上 9 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 1,2,\dots,x です。
- これより、 f(1)=1,f(2)=2,...,f(9)=9 となります。
- 10 以上 16 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 10,11,\dots,x です。
- これより、 f(10)=1,f(11)=2,...,f(16)=7 となります。
結局、求める答えは 73 です。
入力例 2
238
出力例 2
13870
入力例 3
999999999999999999
出力例 3
762062362
998244353 で割った余りを求めることに注意してください。
Score : 300 points
Problem Statement
Given an integer N, solve the following problem.
Let f(x)= (The number of positive integers at most x with the same number of digits as x).
Find f(1)+f(2)+\dots+f(N) modulo 998244353.
Constraints
- N is an integer.
- 1 \le N < 10^{18}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
16
Sample Output 1
73
- For a positive integer x between 1 and 9, the positive integers at most x with the same number of digits as x are 1,2,\dots,x.
- Thus, we have f(1)=1,f(2)=2,...,f(9)=9.
- For a positive integer x between 10 and 16, the positive integers at most x with the same number of digits as x are 10,11,\dots,x.
- Thus, we have f(10)=1,f(11)=2,...,f(16)=7.
The final answer is 73.
Sample Input 2
238
Sample Output 2
13870
Sample Input 3
999999999999999999
Sample Output 3
762062362
Be sure to find the sum modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
この問題は インタラクティブな問題(あなたの作成したプログラムとジャッジシステムが入出力を介して対話を行う形式の問題)です。
整数 N および N 未満の 奇数 K が与えられます。
ジャッジシステムは、0 および 1 からなる長さ N の数列 A = (A_1, A_2, \dots, A_N) を隠し持っています。
あなたは数列 A の要素の値を直接知ることはできません。
その代わりに、ジャッジシステムに対して以下の質問を N 回まで行うことができます。
- 1 以上 N 以下の相異なる整数 x_1, x_2, \dots, x_K を選ぶ。そして、A_{x_1} + A_{x_2} + \dots + A_{x_K} の偶奇を聞く。
N 回以下の質問で (A_1, A_2, \dots, A_N) を全て特定して、答えを出力してください。
ただし、ジャッジは適応的です。言い換えると、ジャッジシステムは今までの質問の回答に矛盾しない範囲でA の内容を自由に変更することができます。
そのため、出力が次の条件を満たす場合にあなたの作成したプログラムは正解とみなされます。それ以外の場合は不正解とみなされます。
- ここまでの質問の回答と矛盾しないような数列が一意に定まっており、かつそれがプログラムが出力した数列と一致している。
制約
- 1 \leq K \lt N \leq 1000
- K は奇数
- A_i は 0 または 1
入出力
この問題はインタラクティブな問題(あなたの作成したプログラムとジャッジシステムが入出力を介して対話を行う形式の問題)です。
最初に、N および K を標準入力から受け取ってください。
N K
次に、(A_1, A_2, \dots, A_N) を全て特定できるまで質問を繰り返してください。
質問は、以下の形式で標準出力に出力してください。ここで x_1, x_2, \dots, x_K は 1 以上 N 以下の相異なる K 個の整数です。
? x_1 x_2 \dots x_K
これに対する応答は、次の形式で標準入力から与えられます。
T
ここで、T は質問に対する答えで、
- T が
0である場合は A_{x_1} + A_{x_2} + \dots + A_{x_K} は偶数であることを、 - T が
1である場合は A_{x_1} + A_{x_2} + \dots + A_{x_K} は奇数であることを意味します。
ただし、x_1, x_2, \dots, x_K が制約を満たしていないか、質問の回数が N 回を超えた場合は T は -1 となります。
ジャッジが -1 を返した場合、プログラムはすでに不正解とみなされています。この場合、ただちにプログラムを終了してください。
A の要素を全て特定できたら、特定した A の要素を以下の形式で出力してください。その後、ただちにプログラムを終了してください。
! A_1 A_2 \dots A_N
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で誤った出力形式による出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
- 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
- ジャッジは適応的です。言い換えると、ジャッジシステムは今までの質問の回答に矛盾しない範囲で A の内容を変更することができます。
入出力例
以下の入出力例は N=5, K=3 の場合の入出力例です。この入出力例の通りに出力するとジャッジ結果は WA になることに注意してください。
入出力例では、プログラムが出力した A = (1, 0, 1, 1, 0) はここまでの質問の回答に矛盾しない数列ですが、例えば (0, 0, 1, 0, 0) もここまでの質問の回答に矛盾しない数列であるため、数列 A は一意に定まっていません。そのため、このプログラムは不正解とみなされます。
| 入力 | 出力 | 説明 |
|---|---|---|
5 3 | まず整数 N および K が与えられます。 | |
? 2 4 1 | (x_1, x_2, x_3) = (2, 4, 1) として質問を行います。 | |
0 | 質問の答えは 0 なので、ジャッジはその値を返します。 | |
? 5 3 2 | (x_1, x_2, x_3) = (5, 3, 2) として質問を行います。 | |
1 | 質問の答えは 1 なので、ジャッジはその値を返します。 | |
! 1 0 1 1 0 | A の答えとして (1, 0, 1, 1, 0) を出力します。A を一意に特定できていないのでジャッジ結果は WA になります。 |
Score : 550 points
Problem Statement
This is an interactive task (where your program and the judge interact via Standard Input and Output).
You are given an integer N and an odd number K.
The judge has a hidden length-N sequence A = (A_1, A_2, \dots, A_N) consisting of 0 and 1.
While you cannot directly access the elements of sequence A, you are allowed to ask the judge the following query at most N times.
- Choose distinct integers x_1, x_2, \dots, and x_K between 1 and N, inclusive, to ask the parity of A_{x_1} + A_{x_2} + \dots + A_{x_K}.
Determine (A_1, A_2, \dots, A_N) by at most N queries, and print the answer.
Here, the judge is adaptive. In other words, the judge may modify the contents of A as long as it is consistent with the responses to the past queries.
Therefore, your program is considered correct if the output satisfies the following condition, and incorrect otherwise:
- your program prints a sequence consistent with the responses to the queries so far, and that is the only such sequence.
Constraints
- 1 \leq K \lt N \leq 1000
- K is odd.
- A_i is 0 or 1.
Input and Output
This is an interactive task (where your program and the judge interact via Standard Input and Output).
First of all, receive N and K from Standard Input.
N K
Then, repeat asking queries until you can uniquely determine (A_1, A_2, \dots, A_N).
Each query should be printed to Standard Output in the following format, where x_1, x_2, \dots, and x_K are K distinct integers between 1 and N, inclusive.
? x_1 x_2 \dots x_K
The response to the query is given from Standard Input in the following format.
T
Here, T denotes the response to the query.
- T is
0when A_{x_1} + A_{x_2} + \dots + A_{x_K} is even, and - T is
1when A_{x_1} + A_{x_2} + \dots + A_{x_K} is odd.
However, if x_1, x_2, \dots and x_K do not satisfy the constraints, or the number of queries exceeds N, then T is -1.
If the judge returns -1, your program is already considered incorrect, so terminate the program immediately.
When you can determine all the elements of A, print those elements in the following format, and terminate the program immediately.
! A_1 A_2 \dots A_N
Notes
- Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
- The verdict will be indeterminate if there is malformed output during the interaction or your program quits prematurely.
- Terminate the program immediately after printing the answer, or the verdict will be indeterminate.
- The judge for this problem is adaptive. This means that the judge may modify the contents of A as long as it is consistent with the responses to the past queries.
Sample Interaction
In the following interaction, N=5 and K=3. Note that the following output itself will result in WA.
Here, A = (1, 0, 1, 1, 0) is indeed consistent with the responses, but so is (0, 0, 1, 0, 0), so sequence A is not uniquely determined. Thus, this program is considered incorrect.
| Input | Output | Description |
|---|---|---|
5 3 | First, you are given integers N and K. | |
? 2 4 1 | You ask a query with (x_1, x_2, x_3) = (2, 4, 1). | |
0 | The response to the query is 0, so the judge returns that value. | |
? 5 3 2 | You ask a query with (x_1, x_2, x_3) = (5, 3, 2). | |
1 | The response to the query is 1, so the judge returns that value. | |
! 1 0 1 1 0 | You print (1, 0, 1, 1, 0) to guess A. Since sequence A is not uniquely determined, the verdict will be WA. |
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
以下の条件を満たす k+1 頂点 k 辺のグラフをレベル k\ (k\geq 2) の星と呼びます。
- ある 1 つの頂点が、他の k 個の頂点と 1 本ずつ辺で結ばれている。それ以外の辺は存在しない。
高橋君は、はじめ何個かの星からなるグラフを持っていました。そして、以下の手続きを全てのグラフの頂点が連結になるまでくり返し行いました。
- 持っているグラフの頂点から二つの頂点を選ぶ。このとき、選んだ二つの頂点の次数は共に 1 であり、かつ選んだ二つの頂点は非連結である必要がある。選んだ二つの頂点を結ぶ辺を張る。
その後、高橋君は手続きが終了した後のグラフの頂点に、適当に 1 から N の番号を付けました。このグラフは木となっており、これを T と呼びます。T には N-1 本の辺があり、 i 番目の辺は u_i と v_i を結んでいました。
その後高橋君は、はじめ持っていた星の個数とレベルを忘れてしまいました。T の情報からはじめ持っていた星の個数とレベルを求めてください。
制約
- 3\leq N\leq 2\times 10^5
- 1\leq u_i, v_i\leq N
- 与えられるグラフは、問題文中の手続きによって得られる N 頂点の木
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
u_1 v_1
\vdots
u_{N-1} v_{N-1}
出力
高橋君が持っていた星が M 個であり、星のレベルがそれぞれ L=(L_1,L_2,\ldots,L_M) であったとする。 このとき、L を昇順に並び替え空白区切りで出力せよ。
なお、この問題では常に解が一意に定まることが証明できる。
入力例 1
6 1 2 2 3 3 4 4 5 5 6
出力例 1
2 2
以下の図のように、2 つのレベル 2 の星から T は得られます。

入力例 2
9 3 9 7 8 8 6 4 6 4 1 5 9 7 3 5 2
出力例 2
2 2 2
入力例 3
20 8 3 8 18 2 19 8 20 9 17 19 7 8 7 14 12 2 15 14 10 2 13 2 16 2 1 9 5 10 15 14 6 2 4 2 11 5 12
出力例 3
2 3 4 7
Score : 475 points
Problem Statement
A graph with (k+1) vertices and k edges is called a level-k\ (k\geq 2) star if and only if:
- it has a vertex that is connected to each of the other k vertices with an edge, and there are no other edges.
At first, Takahashi had a graph consisting of stars. He repeated the following operation until every pair of vertices in the graph was connected:
- choose two vertices in the graph. Here, the vertices must be disconnected, and their degrees must be both 1. Add an edge that connects the chosen two vertices.
He then arbitrarily assigned an integer from 1 through N to each of the vertices in the graph after the procedure. The resulting graph is a tree; we call it T. T has (N-1) edges, the i-th of which connects u_i and v_i.
Takahashi has now forgotten the number and levels of the stars that he initially had. Find them, given T.
Constraints
- 3\leq N\leq 2\times 10^5
- 1\leq u_i, v_i\leq N
- The given graph is an N-vertex tree obtained by the procedure in the problem statement.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
u_1 v_1
\vdots
u_{N-1} v_{N-1}
Output
Suppose that Takahashi initially had M stars, whose levels were L=(L_1,L_2,\ldots,L_M). Sort L in ascending order, and print them with spaces in between.
We can prove that the solution is unique in this problem.
Sample Input 1
6 1 2 2 3 3 4 4 5 5 6
Sample Output 1
2 2
Two level-2 stars yield T, as the following figure shows:

Sample Input 2
9 3 9 7 8 8 6 4 6 4 1 5 9 7 3 5 2
Sample Output 2
2 2 2
Sample Input 3
20 8 3 8 18 2 19 8 20 9 17 19 7 8 7 14 12 2 15 14 10 2 13 2 16 2 1 9 5 10 15 14 6 2 4 2 11 5 12
Sample Output 3
2 3 4 7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 個の都市があり、都市 1, 都市 2, \ldots, 都市 N と番号づけられています。
いくつかの異なる都市の間は一方通行のテレポーターによって移動できます。
都市 i (1\leq i\leq N) からテレポーターによって直接移動できる都市は 0 と 1 からなる長さ M の文字列 S_i によって表されます。具体的には、1\leq j\leq N に対して、
- 1\leq j-i\leq M かつ S_i の (j-i) 文字目が
1ならば、都市 i から都市 j に直接移動できる。 - そうでない時、都市 i から都市 j へは直接移動できない。
k=2,3,\ldots, N-1 に対して次の問題を解いてください。
テレポータを繰り返し使用することによって、都市 k を通らずに都市 1 から 都市 N へ移動できるか判定し、 できるならばそのために必要なテレポーターの使用回数の最小値を、 できないならば -1 を出力せよ。
制約
- 3 \leq N \leq 10^5
- 1\leq M\leq 10
- M<N
- S_i は
0と1のみからなる長さ M の文字列 - i+j>N ならば S_i の j 文字目は
0 - N,M は整数
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
N-2 個の整数を空白区切りで一行に出力せよ。 i (1\leq i\leq N-2) 番目には、k=i+1 に対する問題の答えを出力せよ。
入力例 1
5 2 11 01 11 10 00
出力例 1
2 3 2
テレポータによって各都市からはそれぞれ以下の都市へ直接移動する事ができます。
- 都市 1 からは都市 2,3 へ移動できる。
- 都市 2 からは都市 4 へ移動できる。
- 都市 3 からは都市 4,5 へ移動できる。
- 都市 4 からは都市 5 へ移動できる。
- 都市 5 から移動できる都市は存在しない。
よって、都市 1 から都市 5 へ移動する方法は、
- 経路 1 : 都市 1 \to 都市 2 \to 都市 4 \to 都市 5
- 経路 2 : 都市 1 \to 都市 3 \to 都市 4 \to 都市 5
- 経路 3 : 都市 1 \to 都市 3 \to 都市 5
の 3 つがあり、
- 都市 2 を通らない経路は経路 2, 経路 3 の 2つであり、そのうちテレポーターの使用回数が最小となるのは経路 3 で、この時 2 回使用する。
- 都市 3 を通らない経路は経路 1 のみであり、この時テレポーターは 3 回使用する。
- 都市 4 を通らない経路は経路 3 のみであり、この時テレポーターは 2 回使用する。
となります。よって、2,3,2 をこの順に空白区切りで出力します。
入力例 2
6 3 101 001 101 000 100 000
出力例 2
-1 3 3 -1
都市 1 から都市 6 へ移動する方法は、都市 1 \to 都市 2 \to 都市 5 \to 都市 6 のみであるため、
k=2,5 の場合には都市 k を通らずに都市 1 から都市 6 へ移動する方法は存在せず、
k=3,4 の場合には上の方法が条件をみたし、テレポーターを 3 回使用します。
よって、-1,3,3,-1 をこの順に空白区切りで出力します。
テレポーターは一方通行であるため、
都市 3 から都市 4 へはテレポーターによって移動できますが、
都市 4 から都市 3 へは移動できず、
都市 1 \to 都市 4 \to 都市 3 \to 都市 6
のような移動はできない事に注意してください。
Score : 500 points
Problem Statement
There are N cities numbered city 1, city 2, \ldots, and city N.
There are also one-way teleporters that send you to different cities.
Whether a teleporter can send you directly from city i (1\leq i\leq N) to another is represented by a length-M string S_i consisting of 0 and 1. Specifically, for 1\leq j\leq N,
- if 1\leq j-i\leq M and the (j-i)-th character of S_i is
1, then a teleporter can send you directly from city i to city j; - otherwise, it cannot send you directly from city i to city j.
Solve the following problem for k=2,3,\ldots, N-1:
Can you travel from city 1 to city N without visiting city k by repeatedly using a teleporter? If you can, print the minimum number of times you need to use a teleporter; otherwise, print -1.
Constraints
- 3 \leq N \leq 10^5
- 1\leq M\leq 10
- M<N
- S_i is a string of length M consisting of
0and1. - If i+j>N, then the j-th character of S_i is
0. - N and M are integers.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Print (N-2) integers, separated by spaces, in a single line. The i-th (1\leq i\leq N-2) integer should be the answer to the problem for k=i+1.
Sample Input 1
5 2 11 01 11 10 00
Sample Output 1
2 3 2
A teleporter sends you
- from city 1 to cities 2 and 3;
- from city 2 to city 4;
- from city 3 to cities 4 and 5;
- from city 4 to city 5; and
- from city 5 to nowhere.
Therefore, there are three paths to travel from city 1 to city 5:
- path 1 : city 1 \to city 2 \to city 4 \to city 5;
- path 2 : city 1 \to city 3 \to city 4 \to city 5; and
- path 3 : city 1 \to city 3 \to city 5.
Among these paths,
- two paths, path 2 and path 3, do not visit city 2. Among them, path 3 requires the minimum number of teleporter uses (twice).
- Path 1 is the only path without city 3. It requires using a teleporter three times.
- Path 3 is the only path without city 4. It requires using a teleporter twice.
Thus, 2, 3, and 2, separated by spaces, should be printed.
Sample Input 2
6 3 101 001 101 000 100 000
Sample Output 2
-1 3 3 -1
The only path from city 1 to city 6 is city 1 \to city 2 \to city 5 \to city 6.
For k=2,5, there is no way to travel from city 1 to city 6 without visiting city k.
For k=3,4, the path above satisfies the condition; it requires using a teleporter three times.
Thus, -1, 3, 3, and -1, separated by spaces, should be printed.
Note that a teleporter is one-way;
a teleporter can send you from city 3 to city 4,
but not from city 4 to city 3,
so the following path, for example, is invalid:
city 1 \to city 4 \to city 3 \to city 6.