【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 ...
随机推荐
- AtCoder Grand Contest 001 D - Arrays and Palindrome
题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d 题目大意: 现要求你构造两个序列\(a,b\),满足: \(a\)序列中数字总和为\(N\ ...
- Lightoj 1044 - Palindrome Partitioning (DP)
题目链接: Lightoj 1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...
- bzoj1024 [SCOI2009]生日快乐【dfs】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1024 普通的深搜. #include <cstdio> #include < ...
- CH#56C(LCA+dfs序)
题目传送门 性质是:把节点dfs序以后,异象石按这个序号排序,然后相邻两两求树上距离,这些距离的和除以二就是最小斯坦纳树. 插入删除的具体操作是根据我们上述性质,用一个set维护dfn,比如插入x,则 ...
- new几种用法
在 C# 中,new 关键字可用作运算符.修饰符或约束. new 运算符 用于创建对象和调用构造函数. new 修饰符 用于向基类成员隐藏继承成员. new 约束 用于在泛型声明中约束可能用作类型参数 ...
- 外文翻译 《How we decide》多巴胺的预言 第二节
本节阅读感言:一朝被蛇咬,十年怕井绳.我们的大脑时刻跟新着本体的预测机制. 上一节提到的喇叭,苹果汁实验可以不断的延伸扩展,在播放喇叭前用强光照射...强光照射前放置特定的图片...都可以扩展多巴胺相 ...
- 8.bootstrap下拉菜单、按钮组、按钮式下拉菜单
下拉菜单 dropdown 对齐方式: .dropdown-menu-right .dropdown-menu-left <div class="container" ...
- JS正则表达式匹配<div><style>标签
测试字符串: <style>v\:* { BEHAVIOR: url(#default#VML) } o\:* { BEHA ...
- cnbeta新闻资讯第三方客户端应用
该源码案例是一个cnbeta第三方客户端应用案例,作者ywwxhz,源码cnBeta-reader,cnbeta 的 Android 客户端项目. 源码下载: http://code.662p.com ...
- macos openssl 生成rsa证书 -mark
创建私钥 openssl genrsa -out rsa_private_key.pem 1024 创建无密码私钥 openssl pkcs8 -topk8 -inform PEM –nocrypt ...