Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点之前的所有两点间最短距离和.n<=500 Solution 如果暴力打肯定是会超时的,那就要运用到floyd(hj) floyd算法内2个循环就相当于新加入外循环的那个点然后跟新最短路, 所以可以把题目看成倒过来依次加点,每次\(n^2\)平方更新一下,总共\(O(n^3)\) Code #incl…
Greg and Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between…
http://acm.hdu.edu.cn/showproblem.php?pid=4034 Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2058    Accepted Submission(s): 1030 Problem Description Everyone knows how to calculate the…
Description Everyone knows how to calculate the shortest path in a directed graph. In fact, the opposite problem is also easy. Given the length of shortest path between each pair of vertexes, can you find the original graph?   Input The first line is…
题意: 给出一个 \(n \times m\) 的矩阵,需对其进行黑白染色,使得以下条件成立: 存在区间 \([l,r]\)(\(1\leq l\leq r\leq n\)),使得第 \(l,l+1,\dots,r\) 行恰有 \(2\) 个格子染成黑色,其余行所有格子均为白色. 设第 \(i\) 行染黑的两个格子所在的列为 \(a_i,b_i(a_i\lt b_i)\),那么存在 \(l \leq t \leq r\),使得 \(a_l\geq a_{l+1}\geq a_{l+2}\geq\…
CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找出 \(i\) 号点到 \(j\) 号点的最短路径.则该最短路径只有两种可能: \(i\) 号点直接到达 \(j\) 号点的路径中产生最短路径 \(i\) 号点经过一些中间点到达 \(j\) 号点的路径中产生最短路径 我们添加一个点 \(k\),使得 \(i\) 号点到 \(j\) 号点再添加后产生…
题目链接:1326: Graph 参考博客:HNUSTOJ-1617 Graph(费马数)--G2MI Description Your task is to judge whether a regular polygon can be drawn only by straightedge and compass. The length of the straightedge is infinite. The width of the compass is infinite. The strai…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud  Bubble Sort Graph Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple al…
One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank…
Floyd–Warshall(简称Floyd算法)是一种著名的解决任意两点间的最短路径(All Paris Shortest Paths,APSP)的算法.从表面上粗看,Floyd算法是一个非常简单的三重循环,而且纯粹的Floyd算法的循环体内的语句也十分简洁.我认为,正是由于“Floyd算法是一种动态规划(Dynamic Programming)算法”的本质,才导致了Floyd算法如此精妙.因此,这里我将从Floyd算法的状态定义.动态转移方程以及滚动数组等重要方面,来简单剖析一下图论中这一重…