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
配点 : 250 点
問題文
3 個の数列 A=(A_1,\ldots,A_N), B=(B_1,\ldots,B_M), C=(C_1,\ldots,C_L) が与えられます。
さらに数列 X=(X_1,\ldots,X_Q) が与えられるので、各 i=1,\ldots,Q に対して次の問題を解いてください。
問題:A,B,C からそれぞれ 1 個ずつ要素を選び、和を X_i にすることができるか?
制約
- 1 \leq N,M,L \leq 100
- 0 \leq A_i, B_i ,C_i \leq 10^8
- 1 \leq Q \leq 2\times 10^5
- 0 \leq X_i \leq 3\times 10^8
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N M B_1 \ldots B_M L C_1 \ldots C_L Q X_1 \ldots X_Q
出力
Q 行出力せよ。
i 行目には、A,B,C からそれぞれ 1 個ずつ要素を選び和を X_i にすることができるならば Yes、できないならば No と出力せよ。
入力例 1
3 1 2 3 2 2 4 6 1 2 4 8 16 32 4 1 5 10 50
出力例 1
No Yes Yes No
- A,B,C からそれぞれ 1 個ずつ要素を選び和を 1 にすることはできません。
- A,B,C からそれぞれ 1,2,2 を選ぶと和を 5 にすることができます。
- A,B,C からそれぞれ 2,4,4 を選ぶと和を 10 にすることができます。
- A,B,C からそれぞれ 1 個ずつ要素を選び和を 50 にすることはできません。
Score: 250 points
Problem Statement
You are given three sequences A=(A_1,\ldots,A_N), B=(B_1,\ldots,B_M), and C=(C_1,\ldots,C_L).
Additionally, a sequence X=(X_1,\ldots,X_Q) is given. For each i=1,\ldots,Q, solve the following problem:
Problem: Is it possible to select one element from each of A, B, and C so that their sum is X_i?
Constraints
- 1 \leq N,M,L \leq 100
- 0 \leq A_i, B_i ,C_i \leq 10^8
- 1 \leq Q \leq 2\times 10^5
- 0 \leq X_i \leq 3\times 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N M B_1 \ldots B_M L C_1 \ldots C_L Q X_1 \ldots X_Q
Output
Print Q lines.
The i-th line should contain Yes if it is possible to select one element from each of A, B, and C so that their sum is X_i, and No otherwise.
Sample Input 1
3 1 2 3 2 2 4 6 1 2 4 8 16 32 4 1 5 10 50
Sample Output 1
No Yes Yes No
- It is impossible to select one element from each of A, B, and C so that their sum is 1.
- Selecting 1, 2, and 2 from A, B, and C, respectively, makes the sum 5.
- Selecting 2, 4, and 4 from A, B, and C, respectively, makes the sum 10.
- It is impossible to select one element from each of A, B, and C so that their sum is 50.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
高橋君はゲームをプレイしています。
ゲームは 1,2,\ldots,N の番号がついた N 個のステージからなり、現在はステージ 1 のみを遊ぶことができます。
各ステージ i ( 1\leq i \leq N-1 )が遊べるとき、ステージ i では以下の 2 つのどちらかの行動を行えます。
- A_i 秒掛けてステージ i をクリアする。ステージ i+1 を遊べるようになる。
- B_i 秒掛けてステージ i をクリアする。ステージ X_i を遊べるようになる。
各ステージをクリアするためにかかる時間以外は無視できるとき、ステージ N を遊べるようになるのは最短で何秒後ですか?
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq A_i, B_i \leq 10^9
- 1 \leq X_i \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 B_1 X_1
A_2 B_2 X_2
\vdots
A_{N-1} B_{N-1} X_{N-1}
出力
答えを出力せよ。
入力例 1
5 100 200 3 50 10 1 100 200 5 150 1 2
出力例 1
350
次のように行動することで、350 秒でステージ 5 を遊べるようになります。
- 100 秒掛けてステージ 1 をクリアし、ステージ 2 を遊べるようになる。
- 50 秒掛けてステージ 2 をクリアし、ステージ 3 を遊べるようになる。
- 200 秒掛けてステージ 3 をクリアし、ステージ 5 を遊べるようになる。
入力例 2
10 1000 10 9 1000 10 10 1000 10 2 1000 10 3 1000 10 4 1000 10 5 1000 10 6 1000 10 7 1000 10 8
出力例 2
90
入力例 3
6 1000000000 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1
出力例 3
5000000000
Score: 425 points
Problem Statement
Takahashi is playing a game.
The game consists of N stages numbered 1,2,\ldots,N. Initially, only stage 1 can be played.
For each stage i ( 1\leq i \leq N-1 ) that can be played, you can perform one of the following two actions at stage i:
- Spend A_i seconds to clear stage i. This allows you to play stage i+1.
- Spend B_i seconds to clear stage i. This allows you to play stage X_i.
Ignoring the times other than the time spent to clear the stages, how many seconds will it take at the minimum to be able to play stage N?
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq A_i, B_i \leq 10^9
- 1 \leq X_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 B_1 X_1
A_2 B_2 X_2
\vdots
A_{N-1} B_{N-1} X_{N-1}
Output
Print the answer.
Sample Input 1
5 100 200 3 50 10 1 100 200 5 150 1 2
Sample Output 1
350
By acting as follows, you will be allowed to play stage 5 in 350 seconds.
- Spend 100 seconds to clear stage 1, which allows you to play stage 2.
- Spend 50 seconds to clear stage 2, which allows you to play stage 3.
- Spend 200 seconds to clear stage 3, which allows you to play stage 5.
Sample Input 2
10 1000 10 9 1000 10 10 1000 10 2 1000 10 3 1000 10 4 1000 10 5 1000 10 6 1000 10 7 1000 10 8
Sample Output 2
90
Sample Input 3
6 1000000000 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1
Sample Output 3
5000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
正の整数 N が与えられます。 \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right] の値を求めてください。
ただし、実数 x に対して [x] で x 以下の最大の整数を表します。
制約
- 1 \leq N \leq 10^{12}
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
5
\left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5 です。
入力例 2
10000000000
出力例 2
231802823220
入力や出力が 32 bit 整数型に収まらないことがあることに注意してください。
Score : 500 points
Problem Statement
Given is a positive integer N. Find the value \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right].
Here, for a real number x, [x] denotes the largest integer not exceeding x.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
5
We have \left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5.
Sample Input 2
10000000000
Sample Output 2
231802823220
Note that the input and output may not fit into a 32-bit integer type.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
xy 平面上に高橋くんがいます。 はじめ、高橋くんは点 (s _ x,s _ y) にいます。 高橋くんは、点 (t _ x,t _ y) に移動したいです。
xy 平面上に、長方形 R\coloneqq\lbrace(x,y)\mid a-0.5\leq x\leq b+0.5,c-0.5\leq y\leq d+0.5\rbrace があります。 次の操作を考えます。
- 長方形 R に含まれる格子点 (x,y) をひとつ選ぶ。 点 (x,y) を中心に高橋くんはいまいる位置と対称な位置に瞬間移動する。
上の操作を 0 回以上 10^6 回以下繰り返して、高橋くんが点 (t _ x,t _ y) にいるようにできるか判定してください。 できる場合、高橋くんが点 (t _ x,t _ y) に移動することができるような操作の列を 1 つ構成してください。
制約
- 0\leq s _ x,s _ y,t _ x,t _ y\leq2\times10^5
- 0\leq a\leq b\leq2\times10^5
- 0\leq c\leq d\leq2\times10^5
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
s _ x s _ y t _ x t _ y a b c d
出力
1 行目には、操作を 0 回以上 10^6 回以下繰り返して高橋くんが点 (t _ x,t _ y) に到達できるなら Yes 、そうでなければ No と出力せよ。
1 行目で Yes と出力したとき、かつそのときに限り、あなたが構成した操作列の長さを d としてさらに d 行出力せよ(d は 0\leq d\leq10^6 を満たさなければならない)。
1+i 行目 (1\leq i\leq d) には、i 回目の操作で選んだ点 (x, y)\in R の座標をこの順に空白区切りで出力せよ。
入力例 1
1 2 7 8 7 9 0 3
出力例 1
Yes 7 0 9 3 7 1 8 1
例えば、次のようにして (1,2) から (7,8) へ移動することができます。
- 点 (7,0) を選ぶ。高橋くんは (13,-2) に移動する。
- 点 (9,3) を選ぶ。高橋くんは (5,8) に移動する。
- 点 (7,1) を選ぶ。高橋くんは (9,-6) に移動する。
- 点 (8,1) を選ぶ。高橋くんは (7,8) に移動する。

条件を満たす操作の列であれば何を出力しても正答となるので、例えば
Yes 7 3 9 0 7 2 9 1 8 1
と出力しても正答となります。

入力例 2
0 0 8 4 5 5 0 0
出力例 2
No
どのように操作しても点 (8,4) に移動することはできません。

入力例 3
1 4 1 4 100 200 300 400
出力例 3
Yes
高橋くんがはじめから目的地にいる場合もあります。
入力例 4
22 2 16 7 14 30 11 14
出力例 4
No
Score : 500 points
Problem Statement
Takahashi is on an xy-plane. Initially, he is at point (s _ x,s _ y), and he wants to reach point (t _ x,t _ y).
On the xy-plane is a rectangle R\coloneqq\lbrace(x,y)\mid a-0.5\leq x\leq b+0.5,c-0.5\leq y\leq d+0.5\rbrace. Consider the following operation:
- Choose a lattice point (x,y) contained in the rectangle R. Takahashi teleports to the point symmetric to his current position with respect to point (x,y).
Determine if he can reach point (t _ x,t _ y) after repeating the operation above between 0 and 10^6 times, inclusive. If it is possible, construct a sequence of operations that leads him to point (t _ x,t _ y).
Constraints
- 0\leq s _ x,s _ y,t _ x,t _ y\leq2\times10^5
- 0\leq a\leq b\leq2\times10^5
- 0\leq c\leq d\leq2\times10^5
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
s _ x s _ y t _ x t _ y a b c d
Output
In the first line, print Yes if Takahashi can reach point (t _ x,t _ y) after repeating the operation between 0 and 10^6 times, inclusive, and No otherwise.
If and only if you print Yes in the first line, print d more lines, where d is the length of the sequence of operations you have constructed (d must satisfy 0\leq d\leq10^6).
The (1+i)-th line (1\leq i\leq d) should contain the space-separated coordinates of the point (x, y)\in R, in this order, that is chosen in the i-th operation.
Sample Input 1
1 2 7 8 7 9 0 3
Sample Output 1
Yes 7 0 9 3 7 1 8 1
For example, the following choices lead him from (1,2) to (7,8).
- Choose (7,0). Takahashi moves to (13,-2).
- Choose (9,3). Takahashi moves to (5,8).
- Choose (7,1). Takahashi moves to (9,-6).
- Choose (8,1). Takahashi moves to (7,8).

Any output that satisfies the conditions is accepted; for example, printing
Yes 7 3 9 0 7 2 9 1 8 1
is also accepted.

Sample Input 2
0 0 8 4 5 5 0 0
Sample Output 2
No
No sequence of operations leads him to point (8,4).

Sample Input 3
1 4 1 4 100 200 300 400
Sample Output 3
Yes
Takahashi may already be at the destination in the beginning.
Sample Input 4
22 2 16 7 14 30 11 14
Sample Output 4
No