FOJ Problem 2271 X
Accept: 55 Submit: 200
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
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;
const int N_MAX = + ;
int d[N_MAX][N_MAX];
int dp[N_MAX][N_MAX];
int V, M;//顶点数量,边数
void floyd() {
for (int k = ; k < V; k++)
for (int i = ; i < V; i++)
for (int j = ; j < V; j++)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
int main() {
int T,cs=;
scanf("%d", &T);
while (T--) {
cs++;
scanf("%d%d", &V, &M);
memset(d, 0x3f, sizeof(d));
for (int i = ; i < V; i++) d[i][i] = ;
int res = ;
for (int i = ; i < M; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
a--, b--;
if (d[a][b] == INF) { d[a][b] = c;}
else {//!!一条路有多条边存在
d[a][b] = min(d[a][b], c);
res++; }
d[b][a] = d[a][b];//!!!!!路径双向
} memcpy(dp, d, sizeof(d));
floyd();
for (int i = ; i < V; i++) {
for (int j = i+; j < V; j++) {//!!!!! if (d[i][j] == INF)continue;//两点没有直接连通路,不存在边不需要判断
if (dp[i][j]<d[i][j]) {
res++;
}
else {//相等,也可能i,j之间可以通过i->k->j的路走,这样就可以删掉直接连通路
for (int k = ; k < V; k++) {
if (k == i || k == j)continue;//!!!!!
if (d[i][j] == dp[i][k] + dp[k][j]) {//!!!!!!
res++;
break;
}
}
}
}
}
printf("Case %d: %d\n",cs,res);
}
return ;
}
FOJ Problem 2271 X的更多相关文章
- FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod C Accept: 1368 Submit: 4639Time Limit: 1000 mSec Memory Limit : 32 ...
- 【Floyd最短路】第七届福建省赛 FZU Problem 2271 X
http://acm.fzu.edu.cn/problem.php?pid=2271 [题意] 给定一个n个点和m条边的无向连通图,问最多可以删去多少条边,使得每两个点之间的距离(最短路长度)不变. ...
- FOJ Problem 1016 无归之室
Problem 1016 无归之室 Accept: 926 Submit: 7502Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- FOJ Problem 1015 土地划分
Problem 1015 土地划分 Accept: 823 Submit: 1956Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- foj Problem 2107 Hua Rong Dao
Problem 2107 Hua Rong Dao Accept: 503 Submit: 1054Time Limit: 1000 mSec Memory Limit : 32768 K ...
- foj Problem 2282 Wand
Problem 2282 Wand Accept: 432 Submit: 1537Time Limit: 1000 mSec Memory Limit : 262144 KB Prob ...
- FOJ Problem 2273 Triangles
Problem 2273 Triangles Accept: 201 Submit: 661Time Limit: 1000 mSec Memory Limit : 262144 KB P ...
- foj Problem 2275 Game
Problem D Game Accept: 145 Submit: 844Time Limit: 1000 mSec Memory Limit : 262144 KB Problem D ...
- foj Problem 2283 Tic-Tac-Toe
Prob ...
随机推荐
- couldn't be opened because you don't have permission to view it” 解决方法
I use Xcode6 GM. I encountered the same problem. What I did was to go to Build Options. Then I chang ...
- Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
解决方案: @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 作用://取消数据库配置 但是 在用到数据库的时候记 ...
- html备忘录
上传文件 <form action="/ajax/" method="post" enctype="multipart/form-data&qu ...
- WPF中在后台实现控件样式
加入现在有一个Button的样式如下: <Style TargetType="{x:Type Button}" x:Key="MyButton">. ...
- 判断NumLock键和CapsLock键是否被锁定
实现效果: 知识运用: AIP函数GetKeyState //针对已处理过的按键 在最近一次输入信息时 判断指定虚拟键的状态 intkey:预测试的虚拟键键码 实现代码: [DllImport(&qu ...
- file-leak-detector(文件句柄泄漏)在JDK1.6环境下 weblogic 和 tomcat安装方式以及使用方式
file-leak-detector作者博客详见: http://file-leak-detector.kohsuke.org/ file-leak-detector学习贴: https://blog ...
- 有C++特色的极乐净土
闲的没事瞎打的 在win7下会走调,需要将win7的beep系统文件改成xp的,且主机装有蜂鸣器才能正常收听. beep文件的度盘地址(不过应该没人为了听个这个去改系统文件)(P.S.如果想要尝试,尽 ...
- 第九次第十次作业 网页设计HTML语言之mp3 与mp4音频与视频两次作业,功能在一起也可
参考的网址是: MP3 参考http://www.cnblogs.com/qingyundian/p/7831098.html MP4参考 http://www.cnblogs.com/qingyun ...
- URAL1561 Winnie the Pooh
题目描述: vjudge 题解: 高消(线性基)模$7$. 可以算是板子了. 具体见代码: #include<cstdio> #include<cstring> #includ ...
- 初涉k-d tree
听说k-d tree是一个骗分的好东西?(但是复杂度差评??? 还听说绍一的kdt常数特别小? KDT是什么 KDT的全称是k-degree tree,顾名思义,这是一种处理多维空间的数据结构. 例如 ...