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的价格卖掉这个物品, 如果它有足够的金 ...
随机推荐
- javascript 数组的常用方法总结
前言 主要讨论一下数组的方法, 1.splice和slice的区别 2.pop和push 3.shift和unshift 4.join 5.forEach(es ...
- 原始套接字--icmp相关
icmp请求 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <uni ...
- JSP/Servlet Web 学习笔记 DayFive
ServletConfig <只对当前Servlet有效> (1)在Web容器初始化Servlet实例时,都会为这个Servlet准备一个唯一的ServletConfig实例(俗称Serv ...
- windows系统查找文件-通配符的使用
在windows中可以使用通配符“* ”.“? ”查找文件.对于相同字符开头的单词和相同字符结尾的单词可以用“<”和“ >”通配符查找单词.1.如果要查找: 任意单个字符 :键入 ? 例如 ...
- POJ 2983-Is the Information Reliable
Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...
- [hdu6432]Problem G. Cyclic
题目大意:给你$n$,一种合法的排列为,排列中没有$s[i\%n+1]-s[i]==1$,求合法方案数 题解:容斥,令$f_{i,j}$表示有$i$个元素,至少包含$j$个$s[i\%n+1]-s[i ...
- Multiplication Game(博弈论)
Description Alice and Bob are in their class doing drills on multiplication and division. They quick ...
- 转:Intent与PendingIntent
intent英文意思是意图,pending表示即将发生或来临的事情. PendingIntent这个类用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转. Int ...
- SpringBoot程序启动时执行初始化代码
因项目集成了Redis缓存部分数据,需要在程序启动时将数据加载到Redis中,即初始化数据到Redis. 在SpringBoot项目下,即在容器初始化完毕后执行我们自己的初始化代码. 第一步:创建实现 ...
- 行为型设计模式之备忘录模式(Memento)
结构 意图 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态. 适用性 必须保存一个对象在某一个时刻的(部分)状态, 这样以后需要时 ...