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. 《Cracking the Coding Interview》——第9章:递归和动态规划——题目2

    2014-03-20 02:55 题目:从(0, 0)走到(x, y),其中x.y都是非负整数.每次只能向x或y轴的正方向走一格,那么总共有多少种走法.如果有些地方被障碍挡住不能走呢? 解法1:如果没 ...

  2. TIDB介绍

    TiDB 是什么? TiDB 是一个分布式 NewSQL 数据库.它支持水平弹性扩展.ACID 事务.标准 SQL.MySQL 语法和 MySQL 协议,具有数据强一致的高可用特性,是一个不仅适合 O ...

  3. 解决Navicat for MySQL 连接 Mysql 8.0.11 出现1251- Client does not support authentication protocol 错误

    安装MySQL8.0之后,使用Navicat连接数据库,报1251错误. 上网搜索解决方案,网上说出现这种情况的原因是:mysql8 之前的版本中加密规则是mysql_native_password, ...

  4. winform对图片进行灰度处理

    //图片进行灰度处理 //originalImage为原图像 返回灰度图像 private Bitmap GrayImage(Bitmap originalImage) { ImageAttribut ...

  5. 安装启动Apache2.4后报Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration错误

    LoadModule access_compat_module modules/mod_access_compat.so 取消这一行模块的注释,再重启服务即可. 搜索 mod_access_compa ...

  6. (转) Unreal的HLSL交叉编译-UEAPI

    HLSL Cross Compiler This library compiles High Level Shading Language (HLSL) shader source code into ...

  7. JS计算器(自制)

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

  8. Scala 基础(2)—— 基本数据结构

    1. Scala 的面向对象 在学习 Java 的时候,我们说 Java 是一门面向对象的语言,然而 Java 其实并没有完全遵守“一切皆对象”这一准则. 例如:Java 的8种基本数据类型 & ...

  9. 【bzoj5047】空间传送装置 堆优化Dijkstra

    题目描述 n个点e条边的有向图,每条边是m种类型之一.第i种类型在第x时刻通过所花费的时间为$(a_i*x+b_i)\mod c_i+d_i$.可以在某个点停留.问:在s时刻从1号点出发,到达每个点所 ...

  10. C++11 tuple元组

    C++11 tuple 元组 tuple容器(元组), 是表示元组容器, 是不包含任何结构的,快速而低质(粗制滥造, quick and dirty)的, 可以用于函数返回多个返回值; tuple容器 ...