A - 传奇球员
Time Limit: 2 sec / Memory Limit: 1024 MB
时间限制:2 秒 / 内存限制:1024 MB
配点 : 点
問題文
AtCoder では、レーティング上位 人のハンドルネームには金色の冠が、上位 人のハンドルネームには白金色の冠が表示されます。
在 AtCoder 中,评分最高的人的手柄 会有一个金冠,而评分最高的人的手柄 会有一个白金皇冠。
このコンテストが開始した時点で、アルゴリズム部門での上位 人に入っているプレイヤーのハンドルネームとレーティングは以下のようになっています。
比赛开始时,算法类顶级 选手的姓名和评分如下:
tourist 3858 ksun48 3679 Benq 3658 Um_nik 3648 apiad 3638 Stonefeang 3630 ecnerwala 3613 mnbvmar 3555 newbiedmy 3516 semiexp 3481
上記のプレイヤーのハンドルネーム が与えられるので、その人のレーティングを出力してください。
将给出上述玩家的句柄 ,您可以打印他们的评分。
制約
- はアルゴリズム部門でレーティング上位 人に入っているプレイヤーのハンドルネームのいずれかと等しい。
等于算法部门评分最高的 玩家的句柄之一。
入力
入力は以下の形式で標準入力から与えられる。 输入从标准输入给出,格式如下:
出力
対応するプレイヤーのレーティングを 行で出力せよ。
在一行中 打印相应玩家的评分。
入力例 1
tourist
出力例 1
3858
このコンテストが開始した時点において、 tourist さんのアルゴリズム部門のレーティングは です。
在本次比赛开始时, Mr./Ms. 的算法评分为 。
入力例 2
semiexp
出力例 2
3481
このコンテストが開始した時点において、 semiexp さんのアルゴリズム部門のレーティングは です。
在本次比赛开始时, Mr./Ms. 的算法评分为 。
Score : points 成绩 : points
Problem Statement 问题陈述
In AtCoder, the top rated players' usernames are displayed with a gold crown, and the top-rated player's username is displayed with a platinum crown.
在 AtCoder 中,评分最高的 玩家的用户名以金冠显示,排名靠前的玩家的用户名以白金冠显示。
At the start of this contest, the usernames and ratings of the top rated players in the algorithm category are as follows:
在本次比赛开始时,算法类别中评分最高的 玩家的用户名和评分如下:
tourist 3858 ksun48 3679 Benq 3658 Um_nik 3648 apiad 3638 Stonefeang 3630 ecnerwala 3613 mnbvmar 3555 newbiedmy 3516 semiexp 3481
You are given the username of one of these players. Print that player's rating.
您将获得其中一位玩家的用户名 。打印该玩家的评分。
Constraints 约束
- is equal to one of the usernames of the top rated players in the algorithm category.
等于算法类别中评分最高的 玩家的用户名之一。
Input 输入
The input is given from Standard Input in the following format:
输入从标准输入中给出,格式如下:
Output 输出
Print the rating of the corresponding player in one line.
在一行中打印相应玩家的评级。
Sample Input 1 示例输入 1
tourist
Sample Output 1 示例输出 1
3858
At the start of this contest, the rating of tourist in the algorithm category is .
在本次比赛开始时,算法类别中 游客的评分为 。
Sample Input 2 示例输入 2
semiexp
Sample Output 2 示例输出 2
3481
At the start of this contest, the rating of semiexp in the algorithm category is .
在本次比赛开始时, semiexp 在算法类别中的评分为 。
Time Limit: 2 sec / Memory Limit: 1024 MB
时间限制:2 秒 / 内存限制:1024 MB
配点 : 点
問題文
正整数 が与えられるので、下記で定まる長さ の文字列 を出力してください。
由于 给出了一个正整数,请输出一个长度如下的字符串 。
各 について、 对于每个 ,
- 以上 以下の の約数 であって、 が の倍数であるものが存在するとき、そのような のうち最小のものに対応する数字を とする。(よって、この場合 は
1
、2
、 、9
のいずれかである。)
如果以下的除数 是 的倍数 ,则 是与其中最小的除数相对应的数字 。 (所以,在本例1
中,它要么是9
、2
、 、 或 。 )- そのような が存在しないとき、 は
-
とする。
如果 不存在这样的条件,则 为-
。
制約
- 入力はすべて整数 所有输入均为整数
入力
入力は以下の形式で標準入力から与えられる。 输入从标准输入给出,格式如下:
出力
答えを出力せよ。 打印出答案。
入力例 1
12
出力例 1
1-643-2-346-1
以下で、いくつかの について の決め方を説明します。
以下是一些决定 方法 :
-
について、 以上 以下の の約数 であって が の倍数であるものは、 の 個です。そのうち最小のものは であるので、
1
です。
对于 ,的除数 是 的 倍数 。 其中最小的是 ,所以1
它是 。 -
について、 以上 以下の の約数 であって が の倍数であるものは、 の 個です。そのうち最小のものは であるので、
3
です。
对于 ,的除数 是 的 倍数 。 其中最小的是 ,所以3
它是 。 -
について、 以上 以下の の約数 であって が の倍数であるものは存在しないので、
-
です。
对于 ,没有-
小 于或等于 的 除数 的倍 数。
入力例 2
7
出力例 2
17777771
入力例 3
1
出力例 3
11
Score : points 成绩 : points
Problem Statement 问题陈述
You are given a positive integer . Print a string of length , , defined as follows.
你得到一个正整数 。打印长度 为 、 的字符串,定义如下。
For each , 对于每个 ,
- if there is a divisor of that is between and , inclusive, and is a multiple of , then is the digit corresponding to the smallest such ( will thus be one of
1
,2
, ...,9
);
如果有一个除数 介 于 和 之间,包括 ,并且是 的 倍数,则 是 对应于最小的 such 的数字( 因此将是 ,1
2
, ..., 之一);9
- if no such exists, then is
-
.
如果不存在这样的 条件,则 为-
.
Constraints 约束
- All input values are integers.
所有输入值均为整数。
Input 输入
The input is given from Standard Input in the following format:
输入从标准输入中给出,格式如下:
Output 输出
Print the answer. 打印答案。
Sample Input 1 示例输入 1
12
Sample Output 1 示例输出 1
1-643-2-346-1
We will explain how to determine for some .
我们将解释如何确定 某些 .
-
For , the divisors of between and such that is a multiple of are . The smallest of these is , so
1
.
对于 ,是 的 倍数的 之间的 除数 是 。 其中最小的是 ,所以1
。 -
For , the divisors of between and such that is a multiple of are . The smallest of these is , so
3
.
对于 ,是 的 倍数的 之间的 除数 是 。 其中最小的是 ,所以3
。 -
For , there are no divisors of between and such that is a multiple of , so
-
.
对于 ,没有 之间的 除数 和 是 的 倍数,所以-
。
Sample Input 2 示例输入 2
7
Sample Output 2 示例输出 2
17777771
Sample Input 3 示例输入 3
1
Sample Output 3 示例输出 3
11
C - 虚假的希望
Time Limit: 2 sec / Memory Limit: 1024 MB
时间限制:2 秒 / 内存限制:1024 MB
配点 : 点
問題文
のマス目に から までの数字が書き込まれており、上から 行目、左から 列目 に書き込まれている数字は です。
从到正方形的数字 写在正方形 中,从上到下 一 行和从左到右的列中写 的数字是 。
異なるマスに同じ数字が書き込まれている場合もありますが、同じ数字が縦・横・斜めに つ連続して書き込まれていることはありません。
より厳密には、 について次の条件のすべてが成り立っていることが保証されます。
相同的数字可以写在不同的方块上,但相同的数字不能连续地垂直、水平 或对角线书写。 更准确地说,以下所有条件都保证对 为真 。
- どの についても、 ではない
对于其中任何一个,不是 - どの についても、 ではない
对于其中任何一个,不是 - ではない 莫
- ではない 莫
高橋くんは、それぞれのマスに書かれている数字をランダムな順番で知ります。
高橋くんは、縦・横・斜めの列のうちの つでも次の条件を満たしたときがっかりします。
高桥君以随机顺序学习每个方格上写的数字。 当垂直、水平和对角线行中的任何一个 满足以下条件时,Takahashi 会感到失望:
- はじめに知ったほうの マスに書かれた数字が同じであり、最後に知ったマスに書かれた数字がそれと異なる。
你学习的第一个 单元格上写的数字是相同的,而你知道的最后一个方格上的数字是不同的。
高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を求めてください。
找到高桥君不会失望的概率,并且会知道所有方格上写的数字。
制約
- ではない 莫
- ではない 莫
- ではない 莫
- ではない 莫
入力
入力は以下の形式で標準入力から与えられる。 输入从标准输入给出,格式如下:
出力
高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を 行で出力せよ。
真の値からの絶対誤差が 以下であるとき、正答と判定される。
不要失望,并输出高桥君知道 写在一行所有方格上的数字的概率。 如果与真值的绝对误差 小于或等于 ,则判断答案正确。
入力例 1
3 1 9 2 5 6 2 7 1
出力例 1
0.666666666666666666666666666667
例えば、高橋くんが の順に知った場合、高橋くんはがっかりしてしまいます。
例如,如果高桥君按照 的顺序学习,高桥君会感到失望。
対して、高橋くんが の順に数字を知った場合、がっかりすることなくすべての数字を知ることができます。
另一方面,如果高桥君知道 的顺序数字,他就会知道所有的数字而不会失望。
高橋くんががっかりすることなくすべての数字を知ることができる確率は です。
絶対誤差が 以下であれば正答と判定されるため、 や のように出力しても正解になります。
高桥君能够知道所有数字而不会失望的概率是 。 如果绝对误差 小于或等于 ,则判断为正确答案,因此即使输出 为 或 ,也是正确的。
入力例 2
7 7 6 8 6 8 7 7 6
出力例 2
0.004982363315696649029982363316
入力例 3
3 6 7 1 9 7 5 7 5
出力例 3
0.4
Score : points 成绩 : points
Problem Statement 问题陈述
There is a grid with numbers between and , inclusive, written in each square. The square at the -th row from the top and -th column from the left contains the number .
每个方格中都有一个网 格, 其中 和 之间有数字,包括 和。从顶部开始的第 -行和 从左侧 开始的第 - 列的正方形包含数字 。
The same number may be written in different squares, but not in three consecutive cells vertically, horizontally, or diagonally. More precisely, it is guaranteed that satisfies all of the following conditions.
- does not hold for any .
- does not hold for any .
- does not hold.
- does not hold.
Takahashi will see the numbers written in each cell in random order. He will get disappointed when there is a line (vertical, horizontal, or diagonal) that satisfies the following condition.
- The first two squares he sees contain the same number, but the last square contains a different number.
Find the probability that Takahashi sees the numbers in all the squares without getting disappointed.
Constraints
- does not hold for any .
- does not hold for any .
- does not hold.
- does not hold.
Input
The input is given from Standard Input in the following format:
Output
Print one line containing the probability that Takahashi sees the numbers in all the squares without getting disappointed. Your answer will be considered correct if the absolute error from the true value is at most .
Sample Input 1
3 1 9 2 5 6 2 7 1
Sample Output 1
0.666666666666666666666666666667
For example, if Takahashi sees in this order, he will get disappointed.
On the other hand, if Takahashi sees in this order, he will see all numbers without getting disappointed.
The probability that Takahashi sees all the numbers without getting disappointed is . Your answer will be considered correct if the absolute error from the true value is at most , so outputs such as and would also be accepted.
Sample Input 2
7 7 6 8 6 8 7 7 6
Sample Output 2
0.004982363315696649029982363316
Sample Input 3
3 6 7 1 9 7 5 7 5
Sample Output 3
0.4
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
高橋くんは、 個の単語からなる文章をウィンドウに表示させようとしています。 すべての単語の縦幅は等しく、 番目 の単語の横幅は です。
文章は、横幅 の空白を単語の区切りとしてウィンドウに表示されます。 より厳密には、高橋くんが横幅 のウィンドウに文章を表示しているとき、次の条件が成り立っています。
- 文章はいくつかの行に分かれている。
- 番目の単語は一番上の行の先頭に表示されている。
- 番目 の単語は、 番目の単語の次に間隔を だけ開けて表示されているか、 番目の単語が含まれる行の下の行の先頭に表示されているかの一方である。それ以外の場所に表示されていることはない。
- それぞれの行の横幅は を超えない。ここで、行の横幅とは最も左にある単語の左端から最も右にある単語の右端までの距離を指す。
高橋くんが文章をウィンドウに表示したとき、文章が 行に収まりました。 ウィンドウの横幅としてありえる最小の値を求めてください。
制約
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを 行で出力せよ。
入力例 1
13 3 9 5 2 7 1 8 8 2 1 5 2 3 6
出力例 1
26
ウィンドウの横幅が のとき、以下のようにして与えられた文章を 行に収めることができます。
ウィンドウの横幅が 以下のときは与えられた文章を 行に収めることができないため、 を出力してください。
単語を複数の行にまたがって表示させたり、行の横幅がウィンドウの横幅を上回ったり、単語を並べ替えたりしてはいけないことに注意してください。
入力例 2
10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 2
10000000009
答えが 整数に収まらない場合があることに注意してください。
入力例 3
30 8 8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32 60
出力例 3
189
Score : points
Problem Statement
Takahashi is displaying a sentence with words in a window. All words have the same height, and the width of the -th word is .
The words are displayed in the window separated by a space of width . More precisely, when the sentence is displayed in a window of width , the following conditions are satisfied.
- The sentence is divided into several lines.
- The first word is displayed at the beginning of the top line.
- The -th word is displayed either with a gap of after the -th word, or at the beginning of the line below the line containing the -th word. It will not be displayed anywhere else.
- The width of each line does not exceed . Here, the width of a line refers to the distance from the left end of the leftmost word to the right end of the rightmost word.
When Takahashi displayed the sentence in the window, the sentence fit into or fewer lines. Find the minimum possible width of the window.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in one line.
Sample Input 1
13 3 9 5 2 7 1 8 8 2 1 5 2 3 6
Sample Output 1
26
When the width of the window is , you can fit the given sentence into three lines as follows.
You cannot fit the given sentence into three lines when the width of the window is or less, so print .
Note that you should not display a word across multiple lines, let the width of a line exceed the width of the window, or rearrange the words.
Sample Input 2
10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2
10000000009
Note that the answer may not fit into a integer.
Sample Input 3
30 8 8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32 60
Sample Output 3
189
Time Limit: 3 sec / Memory Limit: 1024 MB
配点 : 点
問題文
高橋君ははじめ高橋君の家におり、これから青木君の家に遊びに行きます。
人の家の間には から までの番号がつけられた 個のバス停があり、高橋君はそれらの間を下記の方法で移動できます。
- 高橋君の家からバス停 まで だけの時間をかけて徒歩で移動できます。
- 各 について、バス停 からは の倍数である時刻それぞれにバスが出発し、そのバスに乗ることで だけの時間をかけてバス停 に移動できます。ここで、 が制約として保証されます。
- バス停 から青木君の家まで、 だけの時間をかけて徒歩で移動できます。
各 に対して下記のクエリを処理してください。
高橋君が高橋君の家を時刻 に出発するときの、高橋君が青木君の家に到着する時刻としてあり得る最も早いものを求めよ。
なお、バスの出発時刻ちょうどにそのバスが出発するバス停に到着した場合であっても、そのバスに乗ることができます。
制約
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
行出力せよ。 について、 行目には 番目のクエリに対する答えを出力せよ。
入力例 1
4 2 3 5 4 6 6 3 1 7 13 0 710511029 136397527 763027379 644706927 447672230
出力例 1
34 22 710511052 136397548 763027402 644706946 447672250
番目のクエリについて、高橋君は下記の通りに移動を行って、時刻 に青木君の家に到着することができます。
- 時刻 に高橋君の家を出発する。
- 高橋君の家から徒歩で移動し、時刻 にバス停 に到着する。
- 時刻 にバス停 を出発するバスに乗り、時刻 にバス停 に到着する。
- 時刻 にバス停 を出発するバスに乗り、時刻 にバス停 に到着する。
- 時刻 にバス停 を出発するバスに乗り、時刻 にバス停 に到着する。
- バス停 から徒歩で移動し、時刻 に青木君の家に到着する。
番目のクエリについて、高橋君は下記の通りに移動を行って、時刻 に青木君の家に到着することができます。
- 時刻 に高橋君の家を出発する。
- 高橋君の家から徒歩で移動し、時刻 にバス停 に到着する。
- 時刻 にバス停 を出発するバスに乗り、時刻 にバス停 に到着する。
- 時刻 にバス停 を出発するバスに乗り、時刻 にバス停 に到着する。
- 時刻 にバス停 を出発するバスに乗り、時刻 にバス停 に到着する。
- バス停 から徒歩で移動し、時刻 に青木君の家に到着する。
Score : points
Problem Statement
Takahashi is initially at his house and is about to visit Aoki's house.
There are bus stops numbered to between the two houses, and Takahashi can move between them in the following ways:
- He can walk from his house to bus stop in units of time.
- For each , a bus departs from bus stop at each time that is a multiple of , and by taking this bus, he can get to bus stop in units of time. Here, the constraints guarantee that .
- Takahashi can walk from bus stop to Aoki's house in units of time.
For each , process the following query.
Find the earliest time that Takahashi can arrive at Aoki's house when he leaves his house at time .
Note that if he arrives at a bus stop exactly at the departure time of a bus, he can take that bus.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. For each , the -th line should contain the answer to the -th query.
Sample Input 1
4 2 3 5 4 6 6 3 1 7 13 0 710511029 136397527 763027379 644706927 447672230
Sample Output 1
34 22 710511052 136397548 763027402 644706946 447672250
For the first query, Takahashi can move as follows to arrive at Aoki's house at time .
- Leave his house at time .
- Walk from his house and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Walk from bus stop and arrive at Aoki's house at time .
For the second query, Takahashi can move as follows and arrive at Aoki's house at time .
- Leave his house at time .
- Walk from his house and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Take the bus departing from bus stop at time and arrive at bus stop at time .
- Walk from bus stop and arrive at Aoki's house at time .
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
頂点の木があります。 番目の頂点が根であり、 番目 の頂点の親は です。
根でない頂点には、敵か薬のどちらか一方が配置されています。 高橋くんは、すべての敵を倒したいです。 はじめ、高橋くんの強さは で、頂点 にいます。 について、 番目の頂点の情報は整数の組 を用いて次のように表されます。
- ならば 番目の頂点には敵がいます。この頂点に高橋くんが初めて訪れたとき、高橋くんの強さが 未満だった場合高橋くんは敵に倒されて敗北し、高橋くんは他の頂点に移動できなくなります。そうでなかった場合、高橋くんは敵を倒し、強さが 上昇します。
- ならば 番目の頂点には薬があります。この頂点に高橋くんが初めて訪れたとき、高橋くんは薬を飲み、強さが 倍になります。(薬がある頂点では、 です。)
薬がある頂点はたかだか 個です。
高橋くんは、隣接する頂点に移動することができます。 高橋くんがすべての敵を倒すことができるか判定してください。
制約
- である頂点は 個以下
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答え(Yes
または No
)を 行で出力せよ。
入力例 1
8 1 2 0 3 2 1 3 3 1 2 0 4 4 1 2 2 1 2 0 5 6 1 5 5 5 1 140 1
出力例 1
Yes
はじめ、木は以下のようになっています。
高橋くんは、頂点 から の順に移動することで、すべての敵を倒すことができます。 このとき、高橋くんがいる頂点と高橋くんの強さは以下の図のように変化します(図では、すでに訪れたことのある頂点への移動は省略しています)。
例えば、頂点 から の順に移動すると、頂点 に訪れた時点での強さが より小さいので高橋くんは敗北してしまい、すべての敵を倒すことができません。
入力例 2
12 1 1 166 619 1 1 17 592 2 1 222 983 2 1 729 338 5 1 747 62 3 1 452 815 3 2 0 1 4 2 0 40 4 1 306 520 6 1 317 591 1 1 507 946
出力例 2
No
入力例 3
12 1 1 1 791 2 2 0 410 2 1 724 790 2 1 828 599 5 2 0 13 3 1 550 803 1 1 802 506 5 1 261 587 6 1 663 329 8 1 11 955 9 1 148 917
出力例 3
Yes
入力例 4
12 1 2 0 1000000000 2 2 0 1000000000 3 2 0 1000000000 4 2 0 1000000000 5 2 0 1000000000 6 2 0 1000000000 7 2 0 1000000000 8 2 0 1000000000 9 2 0 1000000000 10 2 0 1000000000 11 1 1 1
出力例 4
Yes
Score : points
Problem Statement
There is a tree with vertices. The -st vertex is the root, and the parent of the -th vertex is .
Each non-root vertex has an enemy or a medicine on it. Takahashi wants to defeat all the enemies. Initially, his strength is , and he is at vertex . For , the information of the -th vertex is represented by a triple of integers as follows.
- If , there is an enemy at the -th vertex. When Takahashi visits this vertex for the first time, if his strength is less than , Takahashi is defeated by the enemy and loses, after which he cannot move to other vertices. Otherwise, he defeats the enemy, and his strength increases by .
- If , there is a medicine at the -th vertex. When Takahashi visits this vertex for the first time, he takes the medicine, and his strength is multiplied by . (For a vertex with a medicine, .)
There are at most vertices with a medicine.
Takahashi can repeatedly move to an adjacent vertex. Determine if he can defeat all the enemies.
Constraints
- There are at most vertices with .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer (Yes
or No
) in one line.
Sample Input 1
8 1 2 0 3 2 1 3 3 1 2 0 4 4 1 2 2 1 2 0 5 6 1 5 5 5 1 140 1
Sample Output 1
Yes
Initially, the tree looks like this:
Takahashi can defeat all the enemies by moving from vertex to in this order. Here, his position and strength change as shown in the following figure (movements to vertices that have already been visited are omitted).
On the other hand, if he moves from vertex to in this order, for example, his strength when visiting vertex will be less than , so he will lose without defeating all the enemies.
Sample Input 2
12 1 1 166 619 1 1 17 592 2 1 222 983 2 1 729 338 5 1 747 62 3 1 452 815 3 2 0 1 4 2 0 40 4 1 306 520 6 1 317 591 1 1 507 946
Sample Output 2
No
Sample Input 3
12 1 1 1 791 2 2 0 410 2 1 724 790 2 1 828 599 5 2 0 13 3 1 550 803 1 1 802 506 5 1 261 587 6 1 663 329 8 1 11 955 9 1 148 917
Sample Output 3
Yes
Sample Input 4
12 1 2 0 1000000000 2 2 0 1000000000 3 2 0 1000000000 4 2 0 1000000000 5 2 0 1000000000 6 2 0 1000000000 7 2 0 1000000000 8 2 0 1000000000 9 2 0 1000000000 10 2 0 1000000000 11 1 1 1
Sample Output 4
Yes
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
頂点の無向完全グラフ に対して下記の操作を行います。
各 について、頂点 と 頂点 を結ぶ無向辺を削除する。
その後の において、頂点 から頂点 へのパスが存在するかどうかを判定し、 存在する場合は頂点 から 頂点 への最短パスの個数を で割った余りを求めてください。
ここで、頂点 から 頂点 への最短パスとは、頂点 から頂点 へのパスであって含む辺の本数が最小であるものです。
制約
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
操作後の において、頂点 から頂点 へのパスが存在しない場合は -1
を出力し、
存在する場合は頂点 から頂点 への最短パスの個数を で割った余りを出力せよ。
入力例 1
6 7 4 3 1 3 2 4 1 6 4 6 5 1 6 2
出力例 1
3
操作後の における頂点 から頂点 への最短パスは、 本の辺を含む下記の 個のパスです。
- 頂点 頂点 頂点 頂点
- 頂点 頂点 頂点 頂点
- 頂点 頂点 頂点 頂点
入力例 2
4 6 1 2 1 3 1 4 2 3 2 4 3 4
出力例 2
-1
操作後の には辺が 本もありません。
頂点 から頂点 へのパスが存在しないため -1
を出力します。
Score : points
Problem Statement
We will perform the following operation on a complete undirected graph with vertices.
For each , delete the undirected edge connecting vertices and .
Determine if there is a path from vertex to vertex in after the operation. If there is, find the number, modulo , of shortest paths from vertex to vertex .
Here, a shortest path from vertex to vertex is a path from vertex to vertex that contains the minimum number of edges.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If there is no path from vertex to vertex in after the operation, print -1
. If there is, print the number, modulo , of shortest paths from vertex to vertex .
Sample Input 1
6 7 4 3 1 3 2 4 1 6 4 6 5 1 6 2
Sample Output 1
3
In after the operation, the shortest paths from vertex to vertex are the following three, each containing three edges.
- vertex vertex vertex vertex
- vertex vertex vertex vertex
- vertex vertex vertex vertex
Sample Input 2
4 6 1 2 1 3 1 4 2 3 2 4 3 4
Sample Output 2
-1
has no edges after the operation. There is no path from vertex to vertex , so print -1
.