好久没更新博客了,一直懒得动,这次更新一下. 题意大概是:给出一个图,求它的一个一号节点的度数恰好为D的生成树的方案. 一开始随便水了个乱搞贪心,不出意外并没有过. 仔细思考之后,对于这个问题我们可以先不管有一端是1的边,然后在这样的子图中,观察节点联通块的情况. 如上图,我们可以认为{2,5,6},{3,7},{4}分别是一个联通块. 为了保证最后生成树的连通性,显然每个联通块最少要连接一条对节点1的边. 这样一来我们就可以自由地连接剩下的边,当然,要符合生成树的性质,用并查集来判断是否能连接…
这道题还是非常有意思的,题意很简单,就是给定一个图,和图上的双向边,要求1号节点的度(连接边的条数)等于K,求这棵树的生成树. 我们首先要解决,如何让1号节点的度时为k的呢???而且求的是生成树,意思是不是所有边都会选择.那么我们如何选择才能保证1号节点有K个度呢???这里就要考虑联通分量的问题了,我们刨除1号点,那么联通分量的个数,就是我们让图联通的最小个数,因此我们需要用并查集,把点分在不同的联通块内部. 再考虑我们每个联通块,至少需要1条连接1号点的边.不够K再添加连接1号点的边. 然后考…
这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大意:n个点,m条边,对每条边,询问包含此边的最小生成树的边权之和 题解:大部分人都是用LCA写的,这里提供一个更为精妙的做法. 模拟Kruskal算法建MST的过程,先将m条边按边权排序,依次进行判断.若点对(u,v)属于同一个连通块,则加入边{u,v,w}后会形成一个环,把环中最大的边换成w会多产…
E. Minimum spanning tree for each edge time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n …
Codeforces 938G Shortest Path Queries 一张连通图,三种操作 1.给x和y之间加上边权为d的边,保证不会产生重边 2.删除x和y之间的边,保证此边之前存在 3.询问x到y的路径异或最小值 保证图在任意时刻连通 首先连通图路径异或相当于从x到y的任意一条路径再异或上若干个环得到的,只要在dfs过程中把非树边成的环丢到线性基里就好了,其他环一定可以通过这些环异或组合出来 有加边删边操作怎么做呢?线段树时间分治!注意到不能保证在线段树的任意一个节点图是连通的,需要用…
C. Not Equal on a Segment 题目连接: http://www.codeforces.com/contest/622/problem/C Description You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For the i-th query find any position pi (li ≤ pi …
B. Coach 题目连接: http://www.codeforces.com/contest/300/problem/A Description A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university progra…
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/D Description Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of n ×…
Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input Output The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwis…
codeforces 811E Vladik and Entertaining Flags 题面 \(n*m(1<=n<=10, 1<=m<=1e5)\)的棋盘,每个格子有一个值. 定义联通块:联通块中所有格子的值相等,并且格子四联通. \(1e5\)次询问,每次询问子矩形\((1, l, n, r)\)中联通块的数量. 题解 线段树区间合并. \(cnt[rt]\):区间中联通块个数 \(pre[rt][]\):在区间中用并查集维护端点的连通性.在给合并之后的集合重新编号时,要注…