初始的时候有一个只有n个点的图(n <= 1e5), 现在进行m( m <= 1e5 )次操作 每次操作要么添加一条无向边, 要么询问之前结点u和v最早在哪一次操作的时候连通了 /* * Author: Gatevin * Created Time: 2015/11/21 14:02:38 * File Name: Sakura_Chiyo.cpp */ #include<iostream> #include<sstream> #include<fstream&g…
Description standard input/output Statements Alex is known to be very clever, but Walter does not believe that. In order to test Alex, he invented a new game. He gave Alex nnodes, and a list of queries. Walter then gives Alex one query every second,…
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要找一个最小的点集,使得满足这n个区间的条件 Input n 然后li,ri,ci Output 输出最小点集大小 Sample Input 5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1 Sample Output 6 Hint 题意 题解: 线段树+二分+贪心 首先我们贪心一…
题目链接: E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to…
题目链接  2016 ACM-ICPC EC-Final Problem G 题意  给定一个无向图.每个点有一种颜色. 现在给定$q$个询问,每次询问$x$和$w$,求所有能通过边权值不超过$w$的边走到$x$的点的集合中,哪一种颜色的点出现的次数最多. 次数相同时输出编号最小的那个颜色.强制在线. 求哪种颜色可以用线段树合并搞定. 关键是这个强制在线. 当每次询问的时候,我们先要求出最小生成树在哪个时刻恰好把边权值不超过$w$的边都用并查集合并了. 在做最小生成树的时候每合并两个节点,另外开…
[描述] 给你一个图,一共有 N 个点,2*N-2 条有向边. 边目录按两部分给出 1. 开始的 n-1 条边描述了一颗以 1 号点为根的生成树,即每个点都可以由 1 号点 到达. 2. 接下来的 N-1 条边,一定是从 i 到 1(2<=i<=N)的有向边,保证每个点都能到 1 有 q 次询问: 1 x w :表示将第 x 条边的边权修改为 w 2 u v :询问 u 到 v 的最短距离 [输入格式] 第一行是 2 个整数 N,Q,表示一共 N 个点 Q 次询问 接下来是 N-1 行,每行…
题目大意 给你一棵树,有\(n\)个点.有\(q\)个操作,每次要你从\(x\)到\(y\)的路径上选两个点,使得距离\(x\)比较远的点的点权\(-\)距离\(x\)比较近的点的点权最大,然后把这条路径上所有点的点权\(+v\). \(n,q\leq 50000\) 题解 这种题没什么意思,直接树剖就好了. 线段树上每个点记录最大值,最小值,从左往右走和从右往左走的最大收益. 时间复杂度:\(O(n+q\log^2 n)\) 代码 #include<cstdio> #include<c…
ιYou are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3...N-1. We will ask you to perfrom some instructions of the following form: CHANGE i ti : change the cost of the i-th edge to tior QUERY a b : ask f…
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数组求min #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #defi…
You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions can be one…