実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
A, B, C からなる長さ N の文字列 S が与えられます。
S の中で ABC が(連続な)部分文字列として初めて現れる位置を答えてください。すなわち、以下の条件を全て満たす整数 n のうち最小のものを答えてください。
- 1 \leq n \leq N - 2
- S の n 文字目から n+2 文字目までを取り出して出来る文字列は
ABCである。
ただし、ABC が S に現れない場合は -1 を出力してください。
制約
- 3 \leq N \leq 100
- S は
A,B,Cからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の中で ABC が部分文字列として初めて現れる位置を出力せよ。ただし、ABC が S に現れない場合は -1 を出力せよ。
入力例 1
8 ABABCABC
出力例 1
3
S の中で ABC が初めて現れるのは 3 文字目から 5 文字目までの位置です。よって 3 が答えになります。
入力例 2
3 ACB
出力例 2
-1
ABC が S に現れない場合は -1 を出力してください。
入力例 3
20 BBAAABBACAACABCBABAB
出力例 3
13
Score : 100 points
Problem Statement
You are given a string S of length N consisting of A, B, and C.
Find the position where ABC first appears as a (contiguous) substring in S. In other words, find the smallest integer n that satisfies all of the following conditions.
- 1 \leq n \leq N - 2.
- The string obtained by extracting the n-th through (n+2)-th characters of S is
ABC.
If ABC does not appear in S, print -1.
Constraints
- 3 \leq N \leq 100
- S is a string of length N consisting of
A,B, andC.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the position where ABC first appears as a substring in S, or -1 if it does not appear in S.
Sample Input 1
8 ABABCABC
Sample Output 1
3
ABC first appears in S at the 3-rd through 5-th characters of S. Therefore, the answer is 3.
Sample Input 2
3 ACB
Sample Output 2
-1
If ABC does not appear in S, print -1.
Sample Input 3
20 BBAAABBACAACABCBABAB
Sample Output 3
13
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
整数 A,B が与えられるので、 A+B の値を答えてください。
但し、この問題は N 択問題であり、 i 番の選択肢は C_i です。
正解となる 選択肢の番号 を出力してください。
制約
- 入力は全て整数
- 1 \le N \le 300
- 1 \le A,B \le 1000
- 1 \le C_i \le 2000
- C_i は相異なる。すなわち、同じ選択肢が複数存在することはない。
- A+B=C_i なる i が丁度 1 つ存在する。すなわち、正解となる選択肢が必ずただ 1 つ存在する。
入力
入力は以下の形式で標準入力から与えられる。
N A B C_1 C_2 \dots C_N
出力
答えを整数として出力せよ。
入力例 1
3 125 175 200 300 400
出力例 1
2
125+175 = 300 です。
1 番の選択肢は 200 、 2 番の選択肢は 300 、 3 番の選択肢は 400 です。
よって正解となる選択肢の番号は 2 番であり、これを出力します。
入力例 2
1 1 1 2
出力例 2
1
1 択問題である場合もあります。
入力例 3
5 123 456 135 246 357 468 579
出力例 3
5
Score : 100 points
Problem Statement
Given integers A and B, find A+B.
This is a N-choice problem; the i-th choice is C_i.
Print the index of the correct choice.
Constraints
- All values in the input are integers.
- 1 \le N \le 300
- 1 \le A,B \le 1000
- 1 \le C_i \le 2000
- C_i are pairwise distinct. In other words, no two choices have the same value.
- There is exactly one i such that A+B=C_i. In other words, there is always a unique correct choice.
Input
The input is given from Standard Input in the following format:
N A B C_1 C_2 \dots C_N
Output
Print the answer as an integer.
Sample Input 1
3 125 175 200 300 400
Sample Output 1
2
We have 125+175 = 300.
The first, second, and third choices are 200, 300, and 400, respectively.
Thus, the 2-nd choice is correct, so 2 should be printed.
Sample Input 2
1 1 1 2
Sample Output 2
1
The problem may be a one-choice problem.
Sample Input 3
5 123 456 135 246 357 468 579
Sample Output 3
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
チェス盤のどこにコマが置かれているか答えてください。
縦 8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。
- 左から 1 列目にあるマスの名前の 1 文字目は
aである。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目はb,c,d,e,f,g,hである。 - 下から 1 行目にあるマスの名前の 2 文字目は
1である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は2,3,4,5,6,7,8である。
例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。
グリッドの状態を表す長さ 8 の 8 つの文字列 S_1,\ldots,S_8 が与えられます。
S_i の j 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。
制約
- S_i は
.および*のみからなる長さ 8 の文字列である - S_1,\ldots,S_8 の中に文字
*はちょうど 1 つ存在する。
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
出力
答えを出力せよ。
入力例 1
........ ........ ........ ........ ........ ........ ........ *.......
出力例 1
a1
問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。
入力例 2
........ ........ ........ ........ ........ .*...... ........ ........
出力例 2
b3
Score : 200 points
Problem Statement
Locate a piece on a chessboard.
We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.
- The first character of the name of a square in the 1-st column from the left is
a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left isb,c,d,e,f,g,h, respectively. - The second character of the name of a square in the 1-st row from the bottom is
1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is2,3,4,5,6,7,8, respectively.
For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.
You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise.
The character * occurs exactly once among S_1,\ldots,S_8.
Find the name of the square that has a piece on it.
Constraints
- S_i is a string of length 8 consisting of
.and*. - The character
*occurs exactly once among S_1,\ldots,S_8.
Input
The input is given from Standard Input in the following format:
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
Output
Print the answer.
Sample Input 1
........ ........ ........ ........ ........ ........ ........ *.......
Sample Output 1
a1
As explained in the problem statement, the bottom-left square is named a1.
Sample Input 2
........ ........ ........ ........ ........ .*...... ........ ........
Sample Output 2
b3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
1 から N までの番号が付いた N 人のプレイヤーが総当たり戦をしました。この総当たり戦で行われた試合全てについて、二人の一方が勝ち、もう一方が負けました。
総当たり戦の結果は N 個の長さ N の文字列 S_1,S_2,\ldots,S_N によって以下の形式で与えられます。
-
i\neq j のとき、S_i の j 文字目は
o,xのいずれかであり、oのときプレイヤー i がプレイヤー j に勝ったことを、xのときプレイヤー i がプレイヤー j に負けたことを意味する。 -
i=j のとき、S_i の j 文字目は
-である。
総当たり戦で勝った試合数が多いほうが順位が上であり、勝った試合数が同じ場合は、プレイヤーの番号が小さいほうが順位が上となります。 N 人のプレイヤーの番号を順位が高い順に答えてください。
制約
- 2\leq N\leq 100
- N は整数
- S_i は
o,x,-からなる長さ N の文字列 - S_1,\ldots,S_N は問題文中の形式を満たす
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
N 人のプレイヤーの番号を、順位が高い順に空白区切りで出力せよ。
入力例 1
3 -xx o-x oo-
出力例 1
3 2 1
プレイヤー 1 は 0 勝、プレイヤー 2 は 1 勝、プレイヤー 3 は 2 勝なので、プレイヤーの番号は順位が高い順に 3,2,1 です。
入力例 2
7 -oxoxox x-xxxox oo-xoox xoo-ooo ooxx-ox xxxxx-x oooxoo-
出力例 2
4 7 3 1 5 2 6
プレイヤー 4 とプレイヤー 7 はどちらも 5 勝ですが、プレイヤー番号が小さいプレイヤー 4 のほうが順位が上になります。
Score : 200 points
Problem Statement
There are N players numbered 1 to N, who have played a round-robin tournament. For every match in this tournament, one player won and the other lost.
The results of the matches are given as N strings S_1,S_2,\ldots,S_N of length N each, in the following format:
-
If i\neq j, the j-th character of S_i is
oorx.omeans that player i won against player j, andxmeans that player i lost to player j. -
If i=j, the j-th character of S_i is
-.
The player with more wins ranks higher. If two players have the same number of wins, the player with the smaller player number ranks higher. Report the player numbers of the N players in descending order of rank.
Constraints
- 2\leq N\leq 100
- N is an integer.
- S_i is a string of length N consisting of
o,x, and-. - S_1,\ldots,S_N conform to the format described in the problem statement.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the player numbers of the N players in descending order of rank.
Sample Input 1
3 -xx o-x oo-
Sample Output 1
3 2 1
Player 1 has 0 wins, player 2 has 1 win, and player 3 has 2 wins. Thus, the player numbers in descending order of rank are 3,2,1.
Sample Input 2
7 -oxoxox x-xxxox oo-xoox xoo-ooo ooxx-ox xxxxx-x oooxoo-
Sample Output 2
4 7 3 1 5 2 6
Both players 4 and 7 have 5 wins, but player 4 ranks higher because their player number is smaller.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
黒板に整数 N が 1 個書かれています。
高橋君は黒板に書かれている 2 以上の整数が全て無くなるまで以下の一連の操作を繰り返します。
- 黒板に書かれている 2 以上の整数を 1 つ選び x とする。
- 黒板から x を 1 個消す。そして、2 個の整数 \left \lfloor \dfrac{x}{2} \right\rfloor, \left\lceil \dfrac{x}{2} \right\rceil を新たに黒板に書く。
- この一連の操作を行うために高橋君は x 円払う必要がある。
ここで \lfloor a \rfloor は a 以下の整数のうち最大のものを、\lceil a \rceil は a 以上の整数のうち最小のものを意味します。
操作を行えなくなった時点で高橋君が払った金額の総和は何円ですか?
なお、どのような順番で操作を行っても高橋君が払う金額の総和は一定であることが証明できます。
制約
- 2 \leq N \leq 10^{17}
入力
入力は以下の形式で標準入力から与えられる。
N
出力
高橋君が払った金額の総和が何円であるかを出力せよ。
入力例 1
3
出力例 1
5
高橋君が行う操作の一例を挙げると次のようになります。
- はじめ、黒板には 3 が 1 個書かれている。
- 高橋君は 3 を選ぶ。高橋君は 3 円を払い、黒板から 3 を 1 個消して \left \lfloor \dfrac{3}{2} \right\rfloor = 1, \left\lceil \dfrac{3}{2} \right\rceil = 2 を新たに黒板に書く。
- 黒板には 2 が 1 個と 1 が 1 個書かれている。
- 高橋君は 2 を選ぶ。高橋君は 2 円を払い、黒板から 2 を 1 個消して \left \lfloor \dfrac{2}{2} \right\rfloor = 1, \left\lceil \dfrac{2}{2} \right\rceil = 1 を新たに黒板に書く。
- 黒板には 1 が 3 個書かれている。
- 黒板から 2 以上の整数が全て無くなったので操作を終了する。
操作全体で高橋君は 3 + 2 = 5 円払ったので、5 を出力します。
入力例 2
340
出力例 2
2888
入力例 3
100000000000000000
出力例 3
5655884811924144128
Score: 300 points
Problem Statement
There is a single integer N written on a blackboard.
Takahashi will repeat the following series of operations until all integers not less than 2 are removed from the blackboard:
- Choose one integer x not less than 2 written on the blackboard.
- Erase one occurrence of x from the blackboard. Then, write two new integers \left \lfloor \dfrac{x}{2} \right\rfloor and \left\lceil \dfrac{x}{2} \right\rceil on the blackboard.
- Takahashi must pay x yen to perform this series of operations.
Here, \lfloor a \rfloor denotes the largest integer not greater than a, and \lceil a \rceil denotes the smallest integer not less than a.
What is the total amount of money Takahashi will have paid when no more operations can be performed?
It can be proved that the total amount he will pay is constant regardless of the order in which the operations are performed.
Constraints
- 2 \leq N \leq 10^{17}
Input
The input is given from Standard Input in the following format:
N
Output
Print the total amount of money Takahashi will have paid, in yen.
Sample Input 1
3
Sample Output 1
5
Here is an example of how Takahashi performs the operations:
- Initially, there is one 3 written on the blackboard.
- He chooses 3. He pays 3 yen, erases one 3 from the blackboard, and writes \left \lfloor \dfrac{3}{2} \right\rfloor = 1 and \left\lceil \dfrac{3}{2} \right\rceil = 2 on the blackboard.
- There is one 2 and one 1 written on the blackboard.
- He chooses 2. He pays 2 yen, erases one 2 from the blackboard, and writes \left \lfloor \dfrac{2}{2} \right\rfloor = 1 and \left\lceil \dfrac{2}{2} \right\rceil = 1 on the blackboard.
- There are three 1s written on the blackboard.
- Since all integers not less than 2 have been removed from the blackboard, the process is finished.
Takahashi has paid a total of 3 + 2 = 5 yen for the entire process, so print 5.
Sample Input 2
340
Sample Output 2
2888
Sample Input 3
100000000000000000
Sample Output 3
5655884811924144128
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
H 行 W 列のマス目の上に 0 個以上のセンサが配置されています。上から i 行目、左から j 列目のマス目を (i, j) と表記します。
センサが配置されているマス目の情報は長さ W の文字列 S_1, S_2, \ldots, S_H によって与えられ、S_i の j 文字目が # のとき、またそのときに限り (i, j) にセンサが配置されています。
このセンサは上下左右斜めに隣接しているマス目に存在する他のセンサと連動し、一つのセンサとして動作します。
ただし、マス目 (x, y) と (x', y') が上下左右斜めに隣接しているとは、\max(|x-x'|,|y-y'|) = 1 であることを指します。
また、センサ A とセンサ B が連動し、センサ A とセンサ C が連動しているとき、センサ B とセンサ C も連動することに注意してください。
連動するセンサを一つのセンサと見なしたとき、このマス目の上にあるセンサの個数を求めてください。
制約
- 1 \leq H, W \leq 1000
- H, W は整数
- S_i は各文字が
#または.である長さ W の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W S_1 S_2 \vdots S_H
出力
答えを出力せよ。
入力例 1
5 6 .##... ...#.. ....## #.#... ..#...
出力例 1
3
連動しているセンサを一つのセンサと見なしたとき、
- (1,2),(1,3),(2,4),(3,5),(3,6) にあるセンサが連動したもの
- (4,1) にあるセンサ
- (4,3),(5,3) にあるセンサが連動したもの
の 3 つのセンサが存在します。
入力例 2
3 3 #.# .#. #.#
出力例 2
1
入力例 3
4 2 .. .. .. ..
出力例 3
0
入力例 4
5 47 .#..#..#####..#...#..#####..#...#...###...##### .#.#...#.......#.#...#......##..#..#...#..#.... .##....#####....#....#####..#.#.#..#......##### .#.#...#........#....#......#..##..#...#..#.... .#..#..#####....#....#####..#...#...###...#####
出力例 4
7
Score : 300 points
Problem Statement
There are zero or more sensors placed on a grid of H rows and W columns. Let (i, j) denote the square in the i-th row from the top and the j-th column from the left.
Whether each square contains a sensor is given by the strings S_1, S_2, \ldots, S_H, each of length W. (i, j) contains a sensor if and only if the j-th character of S_i is #.
These sensors interact with other sensors in the squares horizontally, vertically, or diagonally adjacent to them and operate as one sensor.
Here, a cell (x, y) and a cell (x', y') are said to be horizontally, vertically, or diagonally adjacent if and only if \max(|x-x'|,|y-y'|) = 1.
Note that if sensor A interacts with sensor B and sensor A interacts with sensor C, then sensor B and sensor C also interact.
Considering the interacting sensors as one sensor, find the number of sensors on this grid.
Constraints
- 1 \leq H, W \leq 1000
- H and W are integers.
- S_i is a string of length W where each character is
#or..
Input
The input is given from Standard Input in the following format:
H W S_1 S_2 \vdots S_H
Output
Print the answer.
Sample Input 1
5 6 .##... ...#.. ....## #.#... ..#...
Sample Output 1
3
When considering the interacting sensors as one sensor, the following three sensors exist:
- The interacting sensors at (1,2),(1,3),(2,4),(3,5),(3,6)
- The sensor at (4,1)
- The interacting sensors at (4,3),(5,3)
Sample Input 2
3 3 #.# .#. #.#
Sample Output 2
1
Sample Input 3
4 2 .. .. .. ..
Sample Output 3
0
Sample Input 4
5 47 .#..#..#####..#...#..#####..#...#...###...##### .#.#...#.......#.#...#......##..#..#...#..#.... .##....#####....#....#####..#.#.#..#......##### .#.#...#........#....#......#..##..#...#..#.... .#..#..#####....#....#####..#...#...###...#####
Sample Output 4
7
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
以下の条件を満たす整数 k を「 250 に似た数」と呼びます。
- k が素数 p<q を使って k=p \times q^3 と表される。
N 以下の「 250 に似た数」は全部でいくつありますか?
制約
- N は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
250
出力例 1
2
- 54 = 2 \times 3^3 なので、「 250 に似た数」です。
- 250 = 2 \times 5^3 なので、「 250 に似た数」です。
250 以下の「 250 に似た数」は、以上の 2 つです。
入力例 2
1
出力例 2
0
入力例 3
123456789012345
出力例 3
226863
Score : 400 points
Problem Statement
Let us regard an integer k as "similar to 250" if the following condition is satisfied:
- k is represented as k=p \times q^3 with primes p<q.
How many integers less than or equal to N are "similar to 250"?
Constraints
- N is an integer between 1 and 10^{18} (inclusive)
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
250
Sample Output 1
2
- 54 = 2 \times 3^3 is "similar to 250".
- 250 = 2 \times 5^3 is "similar to 250".
The two integers above are all the integers "similar to 250".
Sample Input 2
1
Sample Output 2
0
Sample Input 3
123456789012345
Sample Output 3
226863
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
英小文字からなる N 個の文字列 S_1, S_2, \ldots, S_N 、および、英小文字からなる文字列 T が与えられます。
1 以上 N 以下の 2 つの整数からなる組 (i, j) は N^2 個ありますが、そのうち下記の条件を満たすものの個数を出力してください。
- S_i と S_j をこの順に連結して得られる文字列は、T を(連続とは限らない)部分列として含む。
制約
- N は整数
- 1 \leq N \leq 5 \times 10^5
- S_i および T は英小文字からなる長さ 1 以上 5 \times 10^5 以下の文字列
- S_1, S_2, \ldots, S_N の長さの総和は 5 \times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
N T S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
3 bac abba bcb aaca
出力例 1
3
問題文中の条件を満たす組 (i, j) は、下記に示す 3 個の組 (1, 2), (1, 3), (2, 3) です。
- (i, j) = (1, 2) について、S_1 と S_2 をこの順に連結して得られる文字列
abbabcbはbacを部分列として含みます。 - (i, j) = (1, 3) について、S_1 と S_3 をこの順に連結して得られる文字列
abbaaacaはbacを部分列として含みます。 - (i, j) = (2, 3) について、S_2 と S_3 をこの順に連結して得られる文字列
bcbaacaはbacを部分列として含みます。
入力例 2
5 xx x x x x x
出力例 2
25
入力例 3
1 y x
出力例 3
0
入力例 4
10 ms mkgn m hlms vmsle mxsm nnzdhi umsavxlb ffnsybomr yvmm naouel
出力例 4
68
Score : 500 points
Problem Statement
You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters, and a string T consisting of lowercase English letters.
There are N^2 pairs (i, j) of integers between 1 and N, inclusive. Print the number of pairs among them that satisfy the following condition.
- The concatenation of S_i and S_j in this order contains T as a (not necessarily contiguous) subsequence.
Constraints
- N is an integer.
- 1 \leq N \leq 5 \times 10^5
- S_i and T are strings of length 1 to 5 \times 10^5, inclusive, consisting of lowercase English letters.
- The total length of S_1, S_2, \ldots, S_N is at most 5 \times 10^5.
Input
The input is given from Standard Input in the following format:
N T S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
3 bac abba bcb aaca
Sample Output 1
3
The pairs (i, j) that satisfy the condition in the problem statement are (1, 2), (1, 3), (2, 3), as seen below.
- For (i, j) = (1, 2), the concatenation
abbabcbof S_1 and S_2 in this order containsbacas a subsequence. - For (i, j) = (1, 3), the concatenation
abbaaacaof S_1 and S_3 in this order containsbacas a subsequence. - For (i, j) = (2, 3), the concatenation
bcbaacaof S_2 and S_3 in this order containsbacas a subsequence.
Sample Input 2
5 xx x x x x x
Sample Output 2
25
Sample Input 3
1 y x
Sample Output 3
0
Sample Input 4
10 ms mkgn m hlms vmsle mxsm nnzdhi umsavxlb ffnsybomr yvmm naouel
Sample Output 4
68
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
N 頂点の木があります。頂点には 1 から N までの番号が付いており、i 番目の辺は頂点 a_i と頂点 b_i を結んでいます。
x=1,2,\ldots,N に対して次の問題を解いてください。
- 木の頂点の部分集合 V であって空でないものは 2^N-1 通り存在するが、そのうち V による誘導部分グラフの連結成分数が x であるようなものは何通りあるかを 998244353 で割った余りを求めよ。
誘導部分グラフとは
S をグラフ G の頂点の部分集合とします。このとき、G の S による誘導部分グラフとは、頂点集合が S で、辺集合が「G の辺であって両端が S に含まれるものすべて」であるようなグラフです。制約
- 1 \leq N \leq 5000
- 1 \leq a_i \lt b_i \leq N
- 与えられるグラフは木
入力
入力は以下の形式で標準入力から与えられる。
N
a_1 b_1
\vdots
a_{N-1} b_{N-1}
出力
N 行出力せよ。
i 行目には x=i に対する出力をせよ。
入力例 1
4 1 2 2 3 3 4
出力例 1
10 5 0 0
以下の 5 通りでは誘導部分グラフの連結成分数が 2、これら以外では 1 になります。
- V = \{1,2,4\}
- V = \{1,3\}
- V = \{1,3,4\}
- V = \{1,4\}
- V = \{2,4\}
入力例 2
2 1 2
出力例 2
3 0
入力例 3
10 3 4 3 6 6 9 1 3 2 4 5 6 6 10 1 8 5 7
出力例 3
140 281 352 195 52 3 0 0 0 0
Score : 500 points
Problem Statement
You are given a tree with N vertices. The vertices are numbered 1 through N, and the i-th edge connects vertex a_i and vertex b_i.
Solve the following problem for each x=1,2,\ldots,N:
- There are (2^N-1) non-empty subsets V of the tree's vertices. Find the number, modulo 998244353, of such V that the subgraph induced by V has exactly x connected components.
What is an induced subgraph?
Let S be the subset of the vertices of a graph G; then the subgraph of G induced by S is a graph whose vertex set is S and whose edge set consists of all edges of G whose both ends are contained in S.Constraints
- 1 \leq N \leq 5000
- 1 \leq a_i \lt b_i \leq N
- The given graph is a tree.
Input
The input is given from Standard Input in the following format:
N
a_1 b_1
\vdots
a_{N-1} b_{N-1}
Output
Print N lines.
The i-th line should contain the answer for x=i.
Sample Input 1
4 1 2 2 3 3 4
Sample Output 1
10 5 0 0
The induced subgraph will have two connected components in the following five cases and one in the others.
- V = \{1,2,4\}
- V = \{1,3\}
- V = \{1,3,4\}
- V = \{1,4\}
- V = \{2,4\}
Sample Input 2
2 1 2
Sample Output 2
3 0
Sample Input 3
10 3 4 3 6 6 9 1 3 2 4 5 6 6 10 1 8 5 7
Sample Output 3
140 281 352 195 52 3 0 0 0 0