<题目链接>

题目大意:
给定$n$个点的有向完全带权图$(n\leq500)$,现在进行$n$次操作,每次操作从图中删除一个点(每删除一个点,都会将与它相关联的边都删除),问你每次删点之前,图中所有点对的最近距离之和。

解题分析:

删除操作不好实现,逆向思维,从后往前添加点。然后就是利用floyd进行离线处理……感觉对floyd还是理解的不够深刻。

#include <bits/stdc++.h>
using namespace std; const int N = ;
#define pb push_back
#define REP(i,s,t) for(int i=s;i<=t;i++)
typedef long long ll;
ll f[N][N],ans[N];
int n,del[N];
inline void floyd(){
REP(k,,n){
int K=del[k];
REP(i,,n){
int I=del[i];
REP(j,,n){
int J=del[j];
f[I][J]=min(f[I][J],f[I][K]+f[K][J]);
if(i<=k&&j<=k)
ans[k]+=f[I][J];
}
}
}
}
int main(){
cin>>n;
REP(i,,n) REP(j,,n){
cin>>f[i][j];
}
for(int i=n;i>=;i--)cin>>del[i];
floyd();
for(int i=n;i>=;i--)cout<<ans[i]<<" ";
}

CodeForces 295B Greg and Graph (floyd+离线)的更多相关文章

  1. ACM - 最短路 - CodeForces 295B Greg and Graph

    CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找 ...

  2. 那些年我们写过的三重循环----CodeForces 295B Greg and Graph 重温Floyd算法

    Greg and Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  3. Codeforce 295B Greg and Graph(Floyd的深入理解)

    题目链接:http://codeforces.com/problemset/problem/295/B 题目大意:给出n个点的完全有权有向图,每次删去一个点,求删掉该点之前整张图各个点的最短路之和(包 ...

  4. 295B - Greg and Graph (floyd逆序处理)

    题意:给出任意两点之间的距离,然后逐个删除这些点和与点相连的边,问,在每次删除前的所有点对的最短距离之和 分析:首先想到的是floyd,但是如果从前往后处理,复杂度是(500)^4,超时,我们从后往前 ...

  5. [CodeForces - 296D]Greg and Graph(floyd)

    Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点 ...

  6. Codeforces 295 B. Greg and Graph

    http://codeforces.com/problemset/problem/295/B 题意: 给定一个有边权的有向图.再给定一个1~n的排列. 按排列中的顺序依次删除点,问每次删除后,所有点对 ...

  7. Codeforces 459E Pashmak and Graph(dp+贪婪)

    题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...

  8. ural 1091. Tmutarakan Exams 和 codeforces 295 B. Greg and Graph

    ural 1091 题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1091 题意是从1到n的集合里选出k个数,使得这些数满足gcd大于1 ...

  9. codeforces 21D:Traveling Graph

    Description You are given undirected weighted graph. Find the length of the shortest cycle which sta ...

随机推荐

  1. ARM Cortex-M底层技术(3)—编译内核的原理及其应用

    概述: 当前开发中,我使用的Keil开发工具较多(keil526),故以keil为例进行介绍,其他开发环境大同小异. 1. 编译链接的定义 不管我们编写的代码有多么简单,都必须经过「编译 --> ...

  2. 一、ffmpeg理论

    一.ffmpeg三件套 ffprobe看文件属性 ffmpeg 编转码 ffplay 播放器 C:\Users\Bruce\Desktop\Temp\ffmpeg\ffmpeg\ToolPack\ff ...

  3. 树——minimum-depth-of-binary-tree(二叉树的最小深度)

    问题: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the s ...

  4. python如何查看内存占用空间

    我们如何查看变量占用了多少内存空间呢 首先我们引用sys模块,在使用getsizeof()方法 import sys L = [x for x in range(10000)] print(sys.g ...

  5. Flutter-網絡請求

    Flutter 请求网络的三种方式 flutter 请求网络的方式有三种,分别是 Dart 原生的网络请求 HttpClient.第三方网络请求 http以及 Flutter 中的 Dio.我们可以比 ...

  6. 对react的研究0

    对react的研究1.class HelloMessage extends React.Component { render() { return ( <div> Hello {this. ...

  7. [NOIP2014]飞扬的小鸟[DP]

    [NOIP2014]飞扬的小鸟 ——!x^n+y^n=z^n 题目描述: Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画 ...

  8. Python_011(生成器)

    一.生成器 def func(): ") return 222 ret = func() print(ret) #结果 111 222 1)这里面函数体里是返回值return;如果将retu ...

  9. 学习日记3、投机取巧使两个表的数据同时在一个treeGrid中显示

    不多说了直接上代码, $('#List').treegrid({ url: '@Url.Action("GetList")', width: $(window).width() - ...

  10. 28 August

    单调队列复习. 投资 (invest) 给定一带符号整数数列,求长度为 \([s, e]\) 的子区间的和的最大值.(最大子段和) 降二维为一维,for循环枚举区间右端点.预处理前缀和,问题转化为找到 ...