【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 ...
随机推荐
- 1-16使用try-catch捕捉异常
处理异常 可以使用try-catch-处理异常,例如之前的程序可以使用try-catch-处理 package com.monkey1024.exception; import java.io.Fil ...
- 合理设置apache的连接数及进程工作方式
网站在线人数增多,访问时很慢.初步认为是服务器资源不足了,但经反复测试,一旦连接上,不断点击同一个页面上不同的链接,都能迅速打开,这种现象就是说明apache最大连接数已经满了,新的访客只能排队等待有 ...
- qconbeijing2014
http://2014.qconbeijing.com/videoslides.html 周一 周二 周三 周四 周五 周六 2014年5月19日 Deep Dive into Amazon's ...
- sql 防注入插入
var strsql = "insert into Staff_Answer (ExamTitleID,QuestionsID,MultipleChoice,RightOption,Answ ...
- Spring Boot 注册 Servlet 的三种方法,真是太有用了!
本文栈长教你如何在 Spring Boot 注册 Servlet.Filter.Listener. 你所需具备的基础 什么是 Spring Boot? Spring Boot 核心配置文件详解 Spr ...
- 利用JSTL重写查询的jsp页面
利用JSTL重写Java Web MVC实例中的jsp页面 第一步:导入jstl.jar和standard.jar文件
- 实现流水灯以间隔500ms的时间闪烁(系统定时器SysTick实现的精确延时)
/** ****************************************************************************** * @file main.c * ...
- 关于bin和obj文件夹。debug 和release的区别(转)
关于bin和obj文件夹. 楼主hcaihao(影子男孩)2002-05-29 20:04:24 在 .NET技术 / C# 提问 VS.Net会生成bin和obj文件夹以及它们下面的Debug和Re ...
- Struts2 前端与后台之间传值问题
老是被前端与后台之间的传值给弄糊涂了,特此写一篇blog进行总结. 一. 前端向后台传值 (1)属性驱动 属性驱动是指在Action类里,包含表单里对应的字段(字段名称一样),同时设置对应的gette ...
- COGS 2685. 迷妹
★ 输入文件:fans.in 输出文件:fans.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 小钟.小皓和小曦都是著名偶像派OI选手,他们都有很多迷妹. 现 ...