Problem 2271 X

Accept: 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
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 1: 2
Case 2: 0

 Source

第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)

题意:一共m条路,去掉最多的路,使原本任意两点最短路不变,最多可以去掉几条路。因为是任意两点,所以可以用Floyd。
代码:
#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)的更多相关文章

  1. FZU 2221 RunningMan(跑男)

    Problem Description 题目描述 ZB loves watching RunningMan! There's a game in RunningMan called 100 vs 10 ...

  2. (floyd)佛洛伊德算法

    Floyd–Warshall(简称Floyd算法)是一种著名的解决任意两点间的最短路径(All Paris Shortest Paths,APSP)的算法.从表面上粗看,Floyd算法是一个非常简单的 ...

  3. POJ 2139 Six Degrees of Cowvin Bacon (Floyd)

    题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...

  4. [CodeForces - 296D]Greg and Graph(floyd)

    Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点 ...

  5. Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意: 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时, 输入数据结束),然后接下来N行描述第i(1< ...

  6. Floyed(floyd)算法详解

    是真懂还是假懂? Floyed算法:是最短路径算法可以说是最慢的一个. 原理:O(n^3)的for循环,对每一个中间节点k做松弛(寻找更短路径): 但它适合算多源最短路径,即任意两点间的距离. 但sp ...

  7. POJ 2253 Frogger(floyd)

    http://poj.org/problem?id=2253 题意 : 题目是说,有这样一只青蛙Freddy,他在一块石头上,他呢注意到青蛙Fiona在另一块石头上,想去拜访,但是两块石头太远了,所以 ...

  8. hdu1869 六度分离(Floyd)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1869 转载请注明出处:http://blog.csdn.net/u012860063?viewmode ...

  9. Trades FZU - 2281 (贪心)(JAVA)

    题目链接: J - Trades  FZU - 2281 题目大意: 开始有m个金币, 在接下来n天里, ACMeow可以花费ci金币去买一个物品, 也可以以ci的价格卖掉这个物品, 如果它有足够的金 ...

随机推荐

  1. 【志银】NYOJ《题目524》A-B Problem

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=860 My思路: 先用两个字符串储存这两个实数,然后再用另外两个字符串储存去掉符号和前后多 ...

  2. hnust 原石法阵

    问题 F: 原石法阵 时间限制: 1 Sec  内存限制: 128 MB提交: 1098  解决: 161[提交][状态][讨论版] 题目描述 WZH有一个由原石构成的n阶三角形魔法阵,三角形魔法阵如 ...

  3. Android 程序怎么打log

    常见的做法: 1. 定义一个常量(变量)作为是否输出log的flag: 2. 定义一个常量(变量)作为log级别设定: 2. 调试.打包时,按需要调整常量的值,从而控制log打印. 常见代码参考: h ...

  4. hadoop-hdfs(三)

    HDFS概念 1 数据块* HDFS的一个数据块默认是64M,与元数据分开管理. 优点: 数据块的大小设计的较大,所以寻址占传输的时间比例较小,只需要计算传输速度即可. 便于简化管理,利于计算剩余空间 ...

  5. unity射线碰撞检测+LayerMask的使用

    射线在unity中是个很方便的东西,对对象查找.多用于碰撞检测(如:子弹飞行是否击中目标).角色移动等提供了很大的帮助,在此做个总结与大家分享下 ,若有不足欢迎吐槽 好了,话补多说啦,直接进入主题: ...

  6. JS计算器(自制)

    <!doctype html><html><header><meta charset="utf-8"><script src= ...

  7. synflood 模拟工具

    synflood 模拟工具 来源 https://blog.csdn.net/wuzhimang/article/details/54581117 因项目需要,要对主流的几家抗DDoS设备做测评,当然 ...

  8. [poj] 2749 building roads

    原题 2-SAT+二分答案! 最小的最大值,这肯定是二分答案.而我们要2-SATcheck是否在该情况下有可行解. 对于目前的答案limit,首先把爱和恨连边,然后我们n^2枚举每两个点通过判断距离来 ...

  9. let与const区别

    let 1. let有变量提升,但是有约束 2. 会形成暂时性死区(TDZ) 3. 同一个块级作用域内不允许声明相同变量 4. 块级变量 5. let声明的全局变量不是全局对象的属性,var会 6. ...

  10. bzoj2957:楼房重建

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 sol  :首先考虑转化问题,即给你一个斜率序列,让你动态维护单调栈 考虑线段树,令ge ...