codeforces 293E Close Vertices】的更多相关文章

题目链接 正解:点分治+树状数组. 点分治板子题,直接点分以后按照$w$排序,扫指针的时候把$w$合法的路径以$l$为下标加入树状数组统计就行了. 写这道题只是想看看我要写多久..事实证明我确实是老年选手了,这种傻逼题写+调竟然用了$40min$.. #include <bits/stdc++.h> #define il inline #define RG register #define ll long long #define lb(x) (x & -x) #define N (3…
题目传送门 题意:现在有一棵树,每条边的长度都为1,然后有一个权值,求存在多少个(u,v)点对,他们的路劲长度 <= l, 总权重 <= w. 题解: 1.找到树的重心. 2.求出每个点到中心的长度和权值. 3.对所有点都询问出合法点的个数(包括同一颗子树)加到答案上. 4.对于每一棵子树内部都找到合法点的个数从答案中减去. 5.递归处理每一颗子树. 我们现在最大的问题就是怎么计算合法点的个数. 我们把点的信息记录下来之后,按照权重从小到达排序. 然后我们就可以用2个端点维护出 a[l].we…
Codeforces 293E 传送门:https://codeforces.com/contest/293/problem/E 题意: 给你一颗边权一开始为0的树,然后给你n-1次操作,每次给边加上边权,问你n-1次操作后有有多少对点之间的路径长度小于等于l,并且边权和小于等于w 题解: poj1741 点分治裸题是 边权和小于等于k,这里加了一个路径条数的限制 对于这个路径条数和边权的两个限制,我们可以得到两个不等式,可以用点分治得到满足距离的一个数组a 将数组a按照距离从小到大排序后,就可…
题链: http://codeforces.com/contest/293/problem/E题解: 点分治,树状数组 大致思路和 POJ 1741 那道点分治入门题相同, 只是因为多了一个路径的边数限制, 所以在统计答案时, 要用数据结构维护一下在满足距离限制的情况下,有多少点也满足边数限制. 树状数组维护到当前的根(重心)的距离为x时的点的个数. 在calc函数中,记录dep[u]表示u到当前的根(重心)的边数, 然后统计u号点可以和多少点组成合法点对时,就查询树状数中有多少点满足到根的距离…
题目:http://codeforces.com/contest/293/problem/E 仍旧是点分治.用容斥,w的限制用排序+两个指针解决, l 的限制就用树状数组.有0的话就都+1,相对大小不变. 切勿每次memset!!!会T得不行.add(sta[ l ].len)即可,但要判一下(l==r)以防不测.(真的有那种数据!) 最后注意树状数组的范围是L(即L+1),不是n.不然可以尝试: 2 10 12 1 5 #include<iostream> #include<cstdi…
链接 大意: 给定邻接表表示两点是否可以连接, 要求将图连成树, 且边不相交的方案数 n范围比较小, 可以直接区间dp $f[l][r]$表示答案, $g[l][r]$表示区间[l,r]全部连通且l,r间连边的方案 #include <iostream> #include <algorithm> #include <cstdio> #define PER(i,a,n) for(int i=n;i>=a;--i) #define REP(i,a,n) for(int…
\(\\\) \(Description\) 求一个\(N\)个点\(M\)条边的无向图,点度为 \(0\) 的点最多和最少的数量. \(N\le 10^5,M\le \frac {N\times (N-1)}{2}\) \(\\\) \(Solution\) 关于最少的数量,注意到一条边会增加两个点度,所以最多能带来 \(2M\) 个点度,最少的零点度点数就是 \(max(N-2M,0)\). 关于最多的数量,要知道 \(N\) 个点的完全图边数是 \(\frac {N\times (N-1)…
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he…
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard input output: standard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are …
题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The New Year holidays are over, but Resha doesn't want to throw away the N…
D - Chloe and pleasant prizes 链接 http://codeforces.com/contest/743/problem/D 题面 Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponso…
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the g…
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, each of them is painted bla…
这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedron                                                                           time limit per test2 seconds                                             …
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positiv…
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of…
Triangle Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plan…
Mr. Kitayuta's Colorful Graph Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 505B Description Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The…
Ivan and Powers of Two Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 404C Description Valera had an undirected connected graph without self-loops and multiple edges consisting of n ver…
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully sub…
题目链接: http://codeforces.com/contest/161/problem/D D. Distance in Tree time limit per test 3 secondsmemory limit per test 512 megabytes 问题描述 A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is th…
题目链接: http://codeforces.com/problemset/problem/77/C C. Beavermuncher-0xFF time limit per test:3 secondsmemory limit per test:256 megabytes 问题描述 "Eat a beaver, save a tree!" - That will be the motto of ecologists' urgent meeting in Beaverley Hill…
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output You are given a functional graph. It is a directed graph, in which from each vertex goes exactly o…
E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex. You are given a tree with n vertices and a root in t…
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph are playing a two-player game on a triangular board that looks like the following: 1 2 3 4 5 7 8 6 9 10 11 13 14 16 17 12 15 18 At each turn, a playe…
A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not…
E. Minimum spanning tree for each edge 题目连接: http://www.codeforces.com/contest/609/problem/E Description Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges. For each edge (u, v) f…
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/problem/D Description Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a gr…
D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/problem/D Description An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a b…
D. Vitaly and Cycle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/problem/D Description After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an…