【Codeforces 25C】Roads in Berland
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
用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的更多相关文章
- 【29.70%】【codeforces 723D】Lakes in Berland
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 644A】Parliament of Berland
[链接] 我是链接,点我呀:) [题意] 题意 [题解] https://blog.csdn.net/V5ZSQ/article/details/70873661 看这个人的吧. [代码] #incl ...
- 【Codeforces 723D】Lakes in Berland (dfs)
海洋包围的小岛,岛内的有湖,'.'代表水,'*'代表陆地,给出的n*m的地图里至少有k个湖,求填掉面积尽量少的水,使得湖的数量正好为k. dfs找出所有水联通块,判断一下是否是湖(海水区非湖).将湖按 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 746G】New Roads
[题目链接]:http://codeforces.com/problemset/problem/746/G [题意] 给你3个数字n,t,k; 分别表示一棵树有n个点; 这棵树的深度t,以及叶子节点的 ...
- 【CodeForces 567E】President and Roads(最短路)
Description Berland has n cities, the capital is located in city s, and the historic home town of th ...
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【50.00%】【codeforces 602C】The Two Routes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 758A】Holiday Of Equality
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- April Fools Contest 2017 B
Description Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it? Input The i ...
- Tomcat启动后打开页面提示404错误的解决
Eclipse配置并启动Tomcat成功,但有时会访问localhost:8080出现404错误,此时需要修改Tomcat配置.步骤如下: 在Eclipse中双击Tomcat server,打开Tom ...
- 关于bootstrap table的server分页
首先是bootstrap初始化的表格参数: // 初始化Table oTableInit.Init = function() { $('#booksTable').bootstrapTable({ u ...
- list的一些功能
x = [1,5,2,3,4] 1.列表反转序: 函数法: x.reverse()该方法没有返回值但会对列表进行反向排序. 注意 不能y=x.reverse(),会得到None 如果要的话要y=rev ...
- Redis学习笔记1-安装配置
一.Redis安装 Redis官网:http://www.redis.io/download 注意:版本号2.4,2.6,2.8等偶数结尾为稳定版,2.5等为非稳定版本,生成环境应该使用稳定版 下载解 ...
- AJPFX浅谈Java新手问题之缺少良好的编程习惯
★随意地命名 有些新手写程序,当需要定义某个变量名(也可能是函数名.类名.包名等)时,随意地一敲键盘,名字就起好了......若干星期后,碰到某 bug,再来看自己写的代码时,心中暗自嘀咕:“这代码是 ...
- JavaScript——数组的indexOf()方法在IE8中的兼容性问题
昨天在工作中遇到一个问题:数组的indexOf()方法在IE8中无效. 如以下代码在IE8中报错“对象不支持“indexOf”属性或方法”: var arr = [1,2,3]; var index ...
- 解决Android 打包为apk文件时已设置签名,在OPPO手机上安装时却出现“未设置签名”的错误
解决办法:
- LN : leetcode 733 Flood Fill
lc 733 Flood Fill 733 Flood Fill An image is represented by a 2-D array of integers, each integer re ...
- SQL数据库学习,常用语句查询大全
数据库学习 sql server数据库基本概念 使用文件保存数据存在几个缺点: 1.文件的安全性问题: 2.文件不利于查询和对数据的管理: 3.文件不利于存放海量数据 4.文件在程序中控制不方便. 数 ...