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…
题目链接 给一个图, 然后给出每条边的权值和一个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…
倍增练习题. 基环树上倍增一下维护维护最小值和权值和,注意循环的时候$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 Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://codeforces.com/contest/985/problem/F Description You are given a string s of length n consisting of lowercase English letters. For two given strings s an…
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w…
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line…
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the gi…
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d ki…