【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

用floyd思想。
求出来这条新加的边影响到的点对即可。
然后尝试更新点对之间的最短路就好。
更新之后把差值从答案里面减掉。

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 300;
int n;
ll dis[N+10][N+10];
int k;
ll ans = 0; void updata(ll &x,ll y){
if (x>y){
ans-=(x-y);
x = y;
}
} int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++){
cin >> dis[i][j];
if (i<=j) ans += dis[i][j];
}
cin >> k;
for (int i = 1;i <= k;i++){
int x,y,z;
cin >> x >> y >> z;
for (int i1 = 1;i1 <= n;i1++)
for (int i2 = 1;i2<=n;i2++){
updata(dis[x][y],z);
if (dis[x][y]!=dis[y][x]){
dis[y][x] = dis[x][y];
}
updata(dis[i1][i2],dis[i1][x]+dis[y][i2]+z);
if (dis[i1][i2]!=dis[i2][i1]){
dis[i2][i1] = dis[i1][i2];
} }
cout<<ans<<" ";
}
return 0;
}

【Codeforces 25C】Roads in Berland的更多相关文章

  1. 【29.70%】【codeforces 723D】Lakes in Berland

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【Codeforces 644A】Parliament of Berland

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] https://blog.csdn.net/V5ZSQ/article/details/70873661 看这个人的吧. [代码] #incl ...

  3. 【Codeforces 723D】Lakes in Berland (dfs)

    海洋包围的小岛,岛内的有湖,'.'代表水,'*'代表陆地,给出的n*m的地图里至少有k个湖,求填掉面积尽量少的水,使得湖的数量正好为k. dfs找出所有水联通块,判断一下是否是湖(海水区非湖).将湖按 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【codeforces 746G】New Roads

    [题目链接]:http://codeforces.com/problemset/problem/746/G [题意] 给你3个数字n,t,k; 分别表示一棵树有n个点; 这棵树的深度t,以及叶子节点的 ...

  6. 【CodeForces 567E】President and Roads(最短路)

    Description Berland has n cities, the capital is located in city s, and the historic home town of th ...

  7. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【50.00%】【codeforces 602C】The Two Routes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 758A】Holiday Of Equality

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. Java 修改编码格式的几种方式

    1.工作空间 workspase Window→Preferences→General→Workspace→Text file encoding→other→UTF-8 2.项目编码格式 右键项目名→ ...

  2. 转-eclipse管理多个workspace

    Eclipse作为Java开发中最常用的开发工具,大家都很熟悉了,但是,当你做过很多项目后你会发现你的eclipse的package explorer视图下显示的project超级多,这时你可能会关闭 ...

  3. Spark-SQL连接Hive

    第一步:修个Hive的配置文件hive-site.xml 添加如下属性,取消本地元数据服务: <property> <name>hive.metastore.local< ...

  4. (转 )Unity对Lua的编辑器拓展

    转 http://blog.csdn.net/ZhangDi2017/article/details/61203505 当前版本的Unity(截至Unity5.5.x)中TextAsset类不支持后缀 ...

  5. discuz x2.5用户注册后邮箱认证后无法收到邮件或者直接进垃圾箱

    又是一个周末,jquery特效继续折腾我那discuz论坛,我开启了个邮箱验证,恶意注册的太恶心了,没有办法. 能稍微屏蔽点,但是问题来了,据亲们反应,无法收到验证邮件,或者有时间直接进入垃圾箱,这个 ...

  6. Intent实现界面跳转、程序跳转

    一个程序往往由多个界面组成,界面之间的跳转,实质是Activity之间的跳转. 从当前程序跳转到其它程序,实质是启动了目标程序的入口Activity. Intent被称为意图,常用于组件之间的交互,可 ...

  7. 网页尺寸scrollHeight/offsetHeight

    scrollHeight和scrollWidth,获取网页内容高度和宽度. 一.针对IE.Opera: scrollHeight 是网页内容实际高度,可以小于 clientHeight. 二.针对NS ...

  8. 【学习笔记】深入理解js原型和闭包(12)——简介【作用域】

    提到作用域,有一句话大家(有js开发经验者)可能比较熟悉:“javascript没有块级作用域”.所谓“块”,就是大括号“{}”中间的语句.例如if语句: 再比如for语句: 所以,我们在编写代码的时 ...

  9. K-means算法Java实现

    public class KMeansCluster {          private int k;//簇的个数          private int num = 100000;//迭代次数  ...

  10. Java虚拟机性能调优相关

    一.JVM内存模型及垃圾收集算法 1.根据Java虚拟机规范,JVM将内存划分为:New(年轻代)Tenured(年老代)永久代(Perm) 其中New和Tenured属于堆内存,堆内存会从JVM启动 ...