补题链接:https://codeforces.com/gym/103446
E. Strange Integers Input The second line contains n integers A1,A2,⋯,An(1≤Ai≤109), denoting the given integers. Output Example 题意: 思路: D. Strange Fractions Input For each test case: Input one line containing two integers p,q(1≤p,q≤107), denoting the given fraction. Output If solution exists, output one line containing two integers a,b(1≤a,b≤109), or print two zeros in one line if no solution. Example 题意: 思路: G. Edge Groups There are exactly 2 edges in each group Input Following n−1 lines each contains two integers u,v(1≤u It is guaranteed that n is odd and that the given graph is connected. Output Example The 3 edge groups are {1↔2,1↔3},{1↔7,4↔7},{5↔7,6↔7} 题意: 思路: I. Steadily Growing Steam Alice enjoys playing a card game called Steadily Growing Steam (as known as SGS). In this game, each player will play different roles and have different skills. Players get cards from the deck and use them to play the game. Each card has a numeric label ti, the point number. In addition, each card has a value vi. Now Alice is playing this game with Bob. According to the skill of Alice’s role, she can have Bob display n cards from the top of the deck. After that, Bob must choose some cards from the n cards and split the chosen cards into two sets that the sum of the cards’ point numbers in the two sets are equal. In other words, if one of the sets is S and another is T , S∩T=∅ and ∑i∈Sti=∑j∈Ttj (Note that S∪T={1,2,⋯n} is not necessary). Then, Alice gets all of the cards in set S and Bob gets the cards in set T. However, according to the skill of Bob’s role, before choosing the two sets, he can choose at most k different cards and double their point numbers. In other words, he can choose a sequence {a1,a2,⋯,ar},(1≤a1 Alice and Bob are partners in this game. Now given the n cards from the deck, they want to know the maximum possible sum of the values of the cards they finally get. In other words, determine the maximum ∑i∈S∪Tvi among all valid schemes(choose cards to double their point numbers, then choose cards and split them into two sets S,T of the same point number sum) and output it. Input The i+1 line contains two integers vi(|vi|≤109) and ti(1≤ti≤13), denoting the value and the point number of the i-th card, respectively. Output Example Double t1 and choose that S={1},T={3,4}, where the point number sum are both 2, and the sum of the card values is 10+5+6=21. 题意: 思路: H. Life is a Game The world can be regarded as an undirected connected graph of n cities and m undirected roads between the cities. Now you, the life game player, are going to play the life game on the world graph. Initially, you are at the x-th city and of k social ability points. You can earn social ability points by living and working. Specifically, you can earn ai social ability points by living and working in the i-th city. But in this problem, you cannot earn social ability points duplicatedly in one city, so you want to travel the world and earn more social ability points. However, the roads are not easy. Specifically, there is an ability threshold wi for the i-th road, you should be of at least wi social ability points to go through the road. Moreover, Your social ability point will not decrease when passing roads but just need to be at least wi if you want to go through the i-th road. So as you can see, the life game is just living, working and traveling repeatedly. There are q game saves. For each game save, the initial city and social ability point is given and the player has not lived or worked in any city. Now you, the real life game player, need to determine the maximum possible number of social ability points you can have in the end of the game and output it for each given game save. Input The second line contains n integers a1,a2,⋯,an(1≤ai≤104), denoting the bonus social ability points for the cities. Following m lines each contains three integers u,v,w(1≤u Following q lines each contains two integers x,k(1≤x≤n,1≤k≤109), denoting the game saves. Output Example For the first game save, you can reach 4 cities {1,2,3,4} and have 7+3+1+4+1=16 social ability points in the end 题意: 思路: K. Circle of Life Lucky can put some Twinkles on some vertices simultaneously with her magic, but there should be at most one Twinkle in one vertex since the near Twinkles will perish together. Then, every second, each Twinkle will split into two Twinkles simultaneously and they will dash in the opposite directions to the two adjacent vertices. Formally, a Twinkle in vertex u splits into two Twinkles, the left splited Twinkle and the right splited Twinkle. The left splited Twinkle will dash toward the left and reach the vertex u−1. The right splited Twinkle in vertex i and the left splited Twinkle in vertex i+2 will crash in vertex i+1(assuming that vertex i+1 lives no Twinkle). Input Output Otherwise, output one line containing one binary string, denoting the initial configuration you found. Examples For the second case, the configurations will change like this: 题意: 思路: 根据样例的n=2和4,容易猜想n为偶数时都可以构造0110011001(01后面接10,10后面接01即可),这样字符串只要2秒就可以产生循环。 对于n为奇数时,构造010+偶数部分(偶数部分用10开头)。
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Given n integers A1,A2,⋯,An and a parameter k, you should choose some integers Ab1,Ab2,⋯,Abm(1≤b1
The first line contains two integers n,k(1≤n≤105,0≤k≤109), denoting the number of given integers and the given parameter.
Output one line containing one integer, denoting the maximum number of the integers you can choose.
inputCopy
11 2
3 1 4 1 5 9 2 6 5 3 5
outputCopy
4
Note
One possible scheme is to choose {A3=4,A6=9,A7=2,A8=6}.#includeD.Strange Fractions
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Given a positive fraction pq, you should find two positive integers a,b that pq=ab+ba. If no such integers, report it.
The first line contains one integer T(1≤T≤105), denoting the number of test cases.
For each test case:
inputCopy
2
5 2
5 1
outputCopy
1 2
0 0
Note
For the first case, 52=12+21 holds. So one possible solution is a=1,b=2.

#includeG.Edge Groups
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Given an undirected connected graph of n vertices and n−1 edges, where n is guaranteed to be odd. You want to divide all the n−1 edges to n−12 groups under following constraints:
The 2 edges in the same group share a common vertex
Determine the number of valid dividing schemes modulo 998244353. Two schemes are considered different if there are 2 edges that are in the same group in one scheme but not in the same group in the other scheme.
The first line contains one integer n(3≤n≤105), denoting the number of vertices.
Output one line containing one integer, denoting the number of valid dividing schemes modulo 998244353.
inputCopy
7
1 2
1 3
1 7
4 7
5 7
6 7
outputCopy
3
Note
The 3 schemes are:
The 3 edge groups are {1↔2,1↔3},{1↔7,5↔7},{4↔7,6↔7}
The 3 edge groups are {1↔2,1↔3},{1↔7,6↔7},{4↔7,5↔7}#includeI.Steadily Growing Steam
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
The first line contains two integers n(1≤n≤100) and k(0≤k≤n), denoting the number of the displayed cards and the maximum number of cards that Bob can choose to double their point numbers, respectively.
Output one line containing one integer, denoting the maximum sum of the value of the cards that Alice or Bob can get.
inputCopy
4 1
10 1
-5 3
5 1
6 1
outputCopy
21
Note
One possible scheme:
1、不选第i个物品。
2、把第i个物品放入集合1,不翻倍
3、把第i个物品放入集合2,不翻倍
4、把第i个物品放入集合1,翻倍
5、把第i个物品放入集合2,翻倍
数组不够开,所以用滚动数组优化。#includeH.Life is a Game
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Life is a game.
The first line contains three integers n,m,q(1≤n,m,q≤105), denoting the number of cities, roads and game saves respectively.
For each game save, output one line containing one integer, denoting the maximum possible number of social ability points you can have.
inputCopy
8 10 2
3 1 4 1 5 9 2 6
1 2 7
1 3 11
2 3 13
3 4 1
3 6 31415926
4 5 27182818
5 6 1
5 7 23333
5 8 55555
7 8 37
1 7
8 30
outputCopy
16
36
Note
Following is a illustration of the given graph.
For the second game save, you can only reach the initial city {8} and have 30+6=36 social ability points in the end
当你在经过一条边权暂时最大的边后,与你经过的连通块相连的所有比这条边小的边都可以走从而获得可以经过的点的价值。
Kruskal重构树适用于求一个无向图,然后给你个点,让你在只能经过边权大于等于x的边(边有个限制),求能到达的顶点的一些性质(个数,权值最大等等)。。
假设我从1出发,只能经过边权小于等于3的边,那么我就在1的父亲节点里找最后一个小于等于3的边即可(因为这是一个大根堆),然后找到了这个父节点假设为fa,那么fa的子树上的叶子节点都是从1满足限制条件能到达的节点。

那么我们对于某个询问,只需要从对应的叶节点开始往上跳到祖先节点(倍增加速跳),直至跳不过去(即这条边下面的子树的叶子点权和加上初始声望值小于该边边权)。#includeK.Circle of Life
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Your friend Lucky is a little elf. Recently, Lucky discovered a magical creature, she named them “Twinkle”. Lucky has a magical chain of n vertices and n−1 edges, where the vertices are connected by the edges one by one. We assume that the vertices are numbered 1 to n from left to right, and the i-th edge connects vertex i and vertex i+1. She found that Twinkles could live in the magical chain.
The right splited Twinkle will dash toward the right and reach the vertex u+1.
But unluckily, if one side has no vertex, the Twinkle will dash out of the chain and die out(for the left splited Twinkle in vertex 1 and the right splited Twinkle in vertex n). Much more unfortunately, if two Twinkles dash to have a head-on collision (i.e. meet in the same vertex or edge), they will perish together with a tearing crash! Specifically, a crash will happen in two situations:
The right splited Twinkle in vertex i and the left splited Twinkle in vertex i+1 will crash in the i-th edge.
Lucky hopes there’s always some Twinkle living on the chain. In addition, in order to be more convenient for Lucky to check the validity, there should be duplicated configurations within 2n seconds. Specifically, a configuration can be denoted by a binary string S of length n, where Si=1 iff vertex i lives a Twinkle, and Ci denotes the configuration after i seconds. Your task is to find an initial configuration C0 so that for each i(0≤i≤2n),Ci≠00⋯00 and that there exist two integers i,j(0≤i
Input one line containing one integer n(2≤n≤123), denoting the length of the chain.
If there is no solution, just output “Unlucky”(without quotes) in one line.
inputCopy
2
outputCopy
10
inputCopy
4
outputCopy
1000
Note
For the first case, the configurations will change like this:
10→01→10
, where C0=C2 holds.
1000→0100→1010→0001→0010→0101→1000
, where C0=C6 holds.
1、从左到右,有n个节点由n-1条边相连,节点编号分别1-n。初始状态由一个长度为n的01串S给出,S[i]=1表示节点i处有精灵,反之没有,每个节点处最多只有一个精灵。
2、现进行2n次变换,每次变换时所有精灵会同时分裂成两个精灵,其中一个精灵向左移动,另一个精灵向右移动。当两个精灵在节点处或边上相遇时会湮灭。(在节点1处向左移动、在节点n处向右移动的精灵会湮灭)
这样在第一秒时,字符串会变为:100(第3位会与偶数部分开头的1相撞,因此还是为0)+偶数部分。第二秒:010+偶数部分(第二秒即可成功复原)#include