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. 【非原创】tomcat 安装时出现 Failed to install Tomcat7 service

    tomcat 安装时出现 Failed to install Tomcat7 service 今天在安装tomcat时提示 Failed to install Tomcat7 service了,花了大 ...

  2. cloud.cfg_for_centos

    users: - default disable_root: 0 ssh_pwauth: 1 locale_configfile: /etc/sysconfig/i18n mount_default_ ...

  3. 聊聊、AES 和 DES

    AES 和 DES 都是对称加密的一种,但是 DES 的 Key 是 56 位,而 AES 的 Key 有 128,256,512 可选. AES 加密AES String randomKey = & ...

  4. 聊聊、Git 常用命令

    创建本地仓库git initgit add .git commit -m "xxxxx"git remote add origin http://git.xxx.com/xxx.g ...

  5. 软工实践 - 第十九次作业 Alpha 冲刺 (10/10)

    队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10046955.htmlz 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 ...

  6. windows系统查找文件-通配符的使用

    在windows中可以使用通配符“* ”.“? ”查找文件.对于相同字符开头的单词和相同字符结尾的单词可以用“<”和“ >”通配符查找单词.1.如果要查找: 任意单个字符 :键入 ? 例如 ...

  7. hdu 1211 RSA (逆元)

    RSA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  8. [CF1000E]We Need More Bosses

    题目大意:给一张无向图,要求找一对$s$和$t$,使得其路径上的割边是最多的,输出其数量. 题解:把边双缩点以后求树的直径. 卡点:无 C++ Code: #include <cstdio> ...

  9. 架构-UML类图

    在UML 2.0的13种图形中,类图是使用频率最高的UML图之一.Martin Fowler在其著作<UML Distilled: A Brief Guide to the Standard O ...

  10. c# tcplistener 与 client通信 服务端 今天写一下

    using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Lin ...