【Codeforces 404C】Restore Graph】的更多相关文章

[链接] 我是链接,点我呀:) [题意] 每个节点的度数不超过k 让你重构一个图 使得这个图满足 从某个点开始到其他点的最短路满足输入的要求 [题解] 把点按照dep的值分类 显然只能由dep到dep+1连边 设cnt[dep]表示到起点的距离为dep的点的集合 如果cnt[dep].size>cnt[dep+1].size 那么只要把dep层的前cnt[dep+1].size个点和dep+1层的点连就好了 否则 只能让dep层的点每个多连几个dep+1层的点了 [代码] import java…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k - the num…
[链接] 我是链接,点我呀:) [题意] 让你找到所有和x颜色的点中,和该颜色的点颜色不同的相邻的点的个数(重复颜色算一次) 求出哪种颜色的所要求的点的数量最多. [题解] 对于每一条边只会被查到两次. 所以按照题意暴力枚举的时间复杂度就是O(n+m)级别的 至于查重 只要对找过的点打个标记就很好处理的 [代码] import java.io.*; import java.util.*; public class Main { static InputReader in; static Prin…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
[题目链接]:http://codeforces.com/contest/755/problem/E [题意] 给你n个节点; 让你在这些点之间接若干条边;构成原图(要求n个节点都联通) 然后分别求出原图和补图(补图也要求联通)的直径r1和r2 然后要求min(r1,r2)==k; 让你求出符合要求的原图的m条边; [题解] 有个结论; 如果图G的直径超过了3,则它的补图的直径会比3小; 且k=1的时候,是无解的; 因为k=1就说明一张图上只有一条边; n=2的时候,另外一张图上没边,最小值为0…
[题目链接]:http://codeforces.com/problemset/problem/716/D [题意] 给你一张图; 这张图上有一些边的权值未知; 让你确定这些权值(改成一个正整数) 使得s到t的最短路恰好为L [题解] 首先; 算出两个值 temp1->所有的未知边的权值都为1->算出s到t的最短路; temp2->所有的未知边的权值都为INF->算出s到t的最短路; 则必须要有 temp1<=L<=temp2 否则无解; 明白这个之后; 为每一个未知的…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in w…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output 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, e…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output 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 wr…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 e…