题目链接 给一个图, 然后给出每条边的权值和一个k值. 让你求出从每个点出发, 走k次能获得的边权的和以及边权的最小值. 用倍增的思想, 求出每个点走一次能到达的点, 权值和以及最小值, 走两次..四次..八次. 这个很容易计算.然后枚举一下所有点就可以了. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm>…
倍增预处理. 先看一下这张图的结构,因为出度都是$1$,所以路径是唯一的,又因为每个点都有出度,所以必然有环,也就是一直可以走下去. 接下来我们需要记录一些值便于询问: 设$t[i][j]$表示从$i$节点出发,走了${2^j}$步之后,到达的节点编号为$t[i][j]$. 设$s[i][j]$表示从$i$节点出发,走了${2^j}$步之后,路径上的权值和为$s[i][j]$. 设$m[i][j]$表示从$i$节点出发,走了${2^j}$步之后,路径上的权值最小值为$m[i][j]$. 像$RM…
http://codeforces.com/contest/702 题意:n个点,n条边,每个点出边只有一条,问从每个点出发经过k条边的边权和,以及边权最小值 思路: f[i][j] 第i个点出发,经过2^j条边后的相连点 其余类似 二进制巧妙解决问题应用太广了 // #pragma comment(linker, "/STACK:102c000000,102c000000") #include <iostream> #include <cstdio> #inc…
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…
倍增练习题. 基环树上倍增一下维护维护最小值和权值和,注意循环的时候$j$这维作为状态要放在外层循环,平时在树上做的时候一个一个结点处理并不会错,因为之前访问的结点已经全部处理过了. 时间复杂度$O(nlogk)$. Code: #include <cstdio> #include <cstring> using namespace std; typedef long long ll; ; ; const int inf = 0x3f3f3f3f; int n, to[N][Lg]…
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Description You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in…
Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m\) 个联通块的有标号生成树的数量是 \[ n^{m-2}\prod_{i=1}^msize_i \] 其中 \(size_i\) 是第 \(i\) 个联通块的大小. 原理就是考虑 \(prufer\) 编码,先把每个联通块看成一个点,那么序列中每出现一个第 \(i\) 联通块缩成的点,能连的边的数…
思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上差分 ] | Codeforces Round #429(Div 1) 题意: 选择一个边集合,满足某些点度数的奇偶性 分析: 将d = 1的点连成一颗树,不在树上的点都不连边. 可以发现,当某个节点u的所有子节点si均可操控 (u, si) 来满足自身要求 即整棵树上至多只有1个点不满足自身要求,…
Codeforces 题面传送门 & 洛谷题面传送门 首先假设我们已经填好了所有问号处的值怎样判断是否存在一个合法的构造方案,显然对于一种方案能够构造出合法的基环内向森林当且仅当: \(\forall x,(0,x)\) 的个数为 \(x\) 的倍数,否则不能构成若干个长度为 \(x\) 的环. 设 \(mx_y=\max\{x|(x,y)\in S\}\),其中 \(S\) 为所有二元组构成的集合,那么必然有二元组 \((0,y),(1,y),(2,y),\cdots,(mx_y,y)\in…
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th…