Graph HDU - 4467】的更多相关文章

https://vjudge.net/problem/HDU-4467 大概就是,设一个块大小T 对于度数<=T的点,设为1类点,在改变颜色的时候暴力查询与其相邻点,更新答案 对于度数>T的点,设为2类点,分别维护与其相邻的颜色为0/1的点之间的边权和(记录与每个点相连的所有2类点,然后在任意点(注意2类点也要)改变颜色时维护一下与其相连2类点的这个值),改变颜色的时候根据维护的值O(1)可以计算出对答案的修改 说的再简单一点,1类点由自身去更新其他,2类点由其他去更新自身..复杂度很容易发现…
P. T. Tigris is a student currently studying graph theory. One day, when he was studying hard, GS appeared around the corner shyly and came up with a problem: Given a graph with n nodes and m undirected weighted edges, every node having one of two co…
Description P. T. Tigris is a student currently studying graph theory. One day, when he was studying hard, GS appeared around the corner shyly and came up with a problem: Given a graph with n nodes and m undirected weighted edges, every node having o…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4467 题意:给定n个点m条边的无向图,点被染色(黑0/白1),边带边权.然后q个询问.询问分为两种: Change u:把点u的颜色反转(黑变白,白变黑),Asksum a b(a,b的值为0/1):统计所以边的权值和,边的两个点满足一个点的颜色为a,一个点的颜色为b. 思路:考虑暴力的做法.修改可以做法O(1),但是查询就得O(m).所以总复杂度为O(m*q)会TLE.然后考虑图分块.参考HDU…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5313 题意: 给出n个顶点,m条边,问最多添加多少条边使之构成一个完全二分图 存储结构: bitset     [用法详情:http://blog.csdn.net/piaocoder/article/details/47177891] 用时:624ms 思路: 二分图的总边数即:n*m(假设一个有n个点,另一个有m个点) 题目是给出总共的点数为n,间接求最大的边数 想到一个小学题:给出长度为n的绳子,…
Problem Description This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on.The Nya graph is an un…
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has a non-direct graph with n vertices and n+1 edges. Rikka can choose some of the edges (at least one…
4725 思路: 拆点建图跑最短路: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 200005 #define maxn_ 400005 #define maxque 2000005 #define INF 0x3f3f3f3f int n,m,head[maxn_],E[…
题解:考虑贪心地一条一条边添加进去. 当 m \leq n-1m≤n−1 时,我们需要最小化距离为 nn 的点对数,所以肯定是连出一个大小为 m+1m+1 的联通块,剩下的点都是孤立点.在这个联通块中,为了最小化内部的距离和,肯定是连成一个菊花的形状,即一个点和剩下所有点直接相邻. 当 m > n-1m>n−1 时,肯定先用最开始 n-1n−1 条边连成一个菊花,这时任意两点之间距离的最大值是 22.因此剩下的每一条边唯一的作用就是将一对点的距离缩减为 11. 这样我们就能知道了最终图的形状了…
LINK:graph HDU题库里的原题 没做过自闭. 考虑dp 设\(f_{i,j}\)表示前i个点构成j个联通块是树的方案数. 对于一次询问答案即为\(\sum_{j}f_{n,j}j^k\) 考虑如何dp出来 显然每次枚举1号所在的连通块的大小 考虑这个连通块是否构成树 即可. 具体转移不再赘述 需要预处理一下i个点的树的个数 i个点的连通块个数 i个点不是树是连通块的个数. 复杂度\(n^3\) 利用分治NTT来优化可以到 \(n^2log^2\)比较繁杂且不是正解. 正解当然是考虑生成…