FZU-2271 X(Floyd)
Problem 2271 XAccept: 303 Submit: 1209
Time Limit: 1500 mSec Memory Limit : 32768 KB
Problem Description
X is a fully prosperous country, especially known for its complicated transportation networks. But recently, for the sake of better controlling by the government, the president Fat Brother thinks it’s time to close some roads in order to make the transportation system more effective.
Country X has N cities, the cities are connected by some undirected roads and it’s possible to travel from one city to any other city by these roads. Now the president Fat Brother wants to know that how many roads can be closed at most such that the distance between any two cities in country X does not change. Note that the distance between city A and city B is the minimum total length of the roads you need to travel from A to B.
Input
The first line of the date is an integer T (1 <= T <= 50), which is the number of the text cases.
Then T cases follow, each case starts with two numbers N, M (1 <= N <= 100, 1 <= M <= 40000) which describe the number of the cities and the number of the roads in country X. Each case goes with M lines, each line consists of three integers x, y, s (1 <= x, y <= N, 1 <= s <= 10, x is not equal to y), which means that there is a road between city x and city y and the length of it is s. Note that there may be more than one roads between two cities.
Output
For each case, output the case number first, then output the number of the roads that could be closed. This number should be as large as possible.
See the sample input and output for more details.
Sample Input
2 3
1 2 1
1 2 1
1 2 2
3 3
1 2 1
2 3 1
1 3 1
Sample Output
Case 2: 0
Source
第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)
#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
int mapp[150][150];
int flag[150][150];
int dis[150][150];
int diss[150][150];
int sum;
int n,m;
void Floyd(){
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
if(mapp[i][k]==INF)continue;
for(int j=1;j<=n;j++){
if(mapp[i][j]>=mapp[i][k]+mapp[k][j]&&i!=j){
if(dis[i][j]==0&&flag[i][j]==1)
{
sum++;dis[i][j]=dis[j][i]=1;
diss[i][k]=diss[k][i]=diss[k][j]=diss[j][k]=1;
}
mapp[i][j]=mapp[i][k]+mapp[k][j];
mapp[j][i]=mapp[i][j]; }
}
}
}
} int main()
{
std::ios::sync_with_stdio(false);
int t;
cin>>t;
int co=1;
while(t--){ cin>>n>>m;
sum=0;
memset(mapp,INF,sizeof(mapp));
memset(flag,0,sizeof(flag));
memset(dis,0,sizeof(dis));
memset(diss,0,sizeof(diss));
for(int i=0;i<m;i++){
int x,y,s;
cin>>x>>y>>s;
if(flag[x][y]==0){
flag[x][y]=flag[y][x]=1;
mapp[x][y]=mapp[y][x]=s;
}
else{
sum++;
if(mapp[x][y]>s){
mapp[x][y]=mapp[y][x]=s;
}
}
}
Floyd();
int num=0;
/*for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(dis[i][j]==1&&flag[i][j]==1&&diss[i][j]!=1){
sum++;
}
}
}*/
cout<<"Case "<<co++<<": "<<sum<<endl; }
return 0;
}
FZU-2271 X(Floyd)的更多相关文章
- FZU 2221 RunningMan(跑男)
Problem Description 题目描述 ZB loves watching RunningMan! There's a game in RunningMan called 100 vs 10 ...
- (floyd)佛洛伊德算法
Floyd–Warshall(简称Floyd算法)是一种著名的解决任意两点间的最短路径(All Paris Shortest Paths,APSP)的算法.从表面上粗看,Floyd算法是一个非常简单的 ...
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
- [CodeForces - 296D]Greg and Graph(floyd)
Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点 ...
- Stockbroker Grapevine(floyd)
http://poj.org/problem?id=1125 题意: 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时, 输入数据结束),然后接下来N行描述第i(1< ...
- Floyed(floyd)算法详解
是真懂还是假懂? Floyed算法:是最短路径算法可以说是最慢的一个. 原理:O(n^3)的for循环,对每一个中间节点k做松弛(寻找更短路径): 但它适合算多源最短路径,即任意两点间的距离. 但sp ...
- POJ 2253 Frogger(floyd)
http://poj.org/problem?id=2253 题意 : 题目是说,有这样一只青蛙Freddy,他在一块石头上,他呢注意到青蛙Fiona在另一块石头上,想去拜访,但是两块石头太远了,所以 ...
- hdu1869 六度分离(Floyd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1869 转载请注明出处:http://blog.csdn.net/u012860063?viewmode ...
- Trades FZU - 2281 (贪心)(JAVA)
题目链接: J - Trades FZU - 2281 题目大意: 开始有m个金币, 在接下来n天里, ACMeow可以花费ci金币去买一个物品, 也可以以ci的价格卖掉这个物品, 如果它有足够的金 ...
随机推荐
- 【Python】Django学习一:第一个Django程序
项目开发环境 Python 3.6 Django 1.11.5 Django安装 在开始安装Django之前,Django更新比较频繁,所以要选择合适的版本,这里选择Django1.11.5. pip ...
- css 之 border-radius属性
css中给盒子设置圆角可以通过 border-radius 属性来实现(具体原理就不深入探讨了); 在开发过程中都会遇到浏览器兼容问题,这问题其实也不难解决,无非就是加上私有前缀,在这里先忽略掉. ...
- Python学习-前台开发-ajax操作
概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用 一个简单操作需要 ...
- Singleton patterns 单件(创建型模式)
1.模式分类 1.1 从目的来看: • – 创建型(Creational)模式:负责对象创建. • – 结构型(Structural)模式:处理类与对象间的组合. • ...
- HDU 4667 Building Fence 计算几何 凸包+圆
1.三角形的所有端点 2.过所有三角形的端点对所有圆做切线,得到所有切点. 3.做任意两圆的外公切线,得到所有切点. 对上述所有点求凸包,标记每个点是三角形上的点还是某个圆上的点. 求完凸包后,因为所 ...
- Codeforces Round #327 (Div2) A~E
CodeForces 591A 题意:在距离为L的两端A,B,相向发射魔法,a(以P1的速度)-->B,A<--b(以P2的速度).假设a-->B,途中相遇,则返回到原点A<- ...
- Sprint 站立会议(个人)
昨天做: 开Sprint会议确定并绘制Backlog. 今天做: 系统主窗体格局 编程环境搭建(部分) 遇到问题: 缺乏经验,没有好的总体规划. 团队博客园:http://www.cnblogs.co ...
- js 回车触发点击事件
$(document).keyup(function(event){ if(event.keyCode ==13){ $("#submit").trigger("clic ...
- luajit的字节码
http://blog.csdn.net/zzz3265/article/details/41146569 这里写出了luajit的字节码
- 聊聊Python中的GIL
对于广大写Python的人来说,GIL(Global Interpreter Lock, 全局解释器锁)肯定不陌生,但未必清楚GIL的历史和全貌是怎样的,今天我们就来梳理一下GIL. 1. 什么是GI ...