CF295B Greg and Graph(离线+Floyd)
来源:互联网 发布:李嘉诚撤资 知乎 编辑:程序博客网 时间:2024/05/19 21:01
每次删一个点,询问最短路长度和。离线后,倒着做,一个点一个点往里加,做floyd即可。
#include <bits/stdc++.h>using namespace std;#define N 510#define inf 0x3f3f3f3f#define ll long longinline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,a[N],d[N][N];ll ans[N];bool f[N];int main(){// freopen("a.in","r",stdin); n=read(); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) d[i][j]=read(); for(int i=1;i<=n;++i) a[i]=read(); for(int kk=n;kk>=1;--kk){ int k=a[kk];f[k]=1; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j){ if(i==j) continue; if(d[i][k]+d[k][j]<d[i][j]) d[i][j]=d[i][k]+d[k][j]; if(f[i]&&f[j]) ans[kk]+=d[i][j]; } } for(int i=1;i<=n;++i) printf("%I64d ",ans[i]); return 0;}
阅读全文
0 0
- CF295B Greg and Graph(离线+Floyd)
- 【CodeForces】295B Greg and Graph 离线算法 Floyd
- CodeForces - 295B D - Greg and Graph(floyd算法)
- Codeforces Round #179 (Div. 2)---D. Greg and Graph(离线+floyd)
- [CF]295B. Greg and Graph | Floyd
- Greg and Graph+floyd算法的应用
- 【codeforces 295B】Greg and Graph ( floyd )
- [Codeforces 295B]Greg and Graph(Floyd)
- CodeForces 295B - Greg and Graph Floyd的巧妙应用
- codeforces 295B B. Greg and Graph(floyd+dp)
- Codeforces 296D Greg And Graph (逆向处理)Floyd
- Codeforces 296D Greg and Graph【Floyd+逆序思维】好题
- Cf #179 (Div. 1) B. Greg and Graph 活用三重floyd
- codeforces 295B Greg and Graph
- Codeforces 295B Greg and Graph
- codeforces 295B Greg and Graph [Floyed]
- 那些年我们写过的三重循环----CodeForces 295B Greg and Graph 重温Floyd算法
- Codeforces 296D/295B(Greg and Graph)
- 十三、Shell函数:Shell函数返回值、删除函数、在终端调用函数
- mysql的内连接和外连接小例子
- msbuild.exe参数(.net 2.0)
- c++继承和派生
- cookie和session详解
- CF295B Greg and Graph(离线+Floyd)
- javabean的使用原则
- centos mongodb 3.4 认证配置
- 调整Linux系统时区
- swift 自定义cell -----------------------简单学习--------第一篇
- IDEA文件编码修改
- 对象,方法的调用
- 自媒体时代的5种淘客模式分析
- 98DX3236初始化脚本程序