Heavy Transportation---poj1797
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#define INF 0xfffffff
#define N 1100
using namespace std; int n,m,dist[N],vis[N];
int maps[N][N]; void Init()
{
int i,j;
memset(vis,,sizeof(vis));
for(i=;i<=n;i++)
{
dist[i]=;
for(j=;j<=n;j++)
{
maps[i][j]=;
}
}
} void Dij(int Start,int End)
{
int Max,index,i,j;
dist[Start] = INF;
for(i = ; i <= n; i++)
{
index=-;
Max=;
for(j = ; j <= n; j++)
{
if(vis[j] == && Max < dist[j])
{
Max = dist[j];
index = j;
}
}
if(index == -)break;
vis[index] = ;
for(j = ; j <= n; j++)
{
if(vis[j] == &&dist[j] < min(dist[index],maps[index][j])) dist[j] = min(dist[index],maps[index][j]);
}
}
} int main()
{
int T,t=,a,b,c;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m); Init(); while(m--)
{
scanf("%d%d%d",&a,&b,&c); maps[a][b] = maps[b][a] = max(maps[a][b],c);
}
Dij(,n); printf("Scenario #%d:\n%d\n\n",t++,dist[n]);
}
return ;
}
下面是相当于求最大生成树的方法
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
using namespace std;
#define N 1210
#define INF 0xfffffff int dist[N], maps[N][N], vis[N], n, ans;
void Dij(int s, int e)
{
for(int i=; i<=n; i++)
dist[i] = maps[s][i];
for(int i=; i<=n; i++)
{
int Max = , Index = -;
for(int j=; j<=n; j++)
{
if(vis[j]== && Max<dist[j])
{
Max = dist[j];
Index=j;
}
}
if(Index == -)break; vis[Index]=; ans=min(ans, dist[Index]); if(Index==n)return ; for(int j=; j<=n; j++)
{
if(vis[j]== && dist[j]<maps[Index][j])
dist[j] = maps[Index][j];
}
}
}
int main()
{
int T, t=, m, a, c, b;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
memset(vis, , sizeof(vis));
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
maps[i][j]=;
dist[i]=maps[i][i]=;
}
for(int i=; i<=m; i++)
{
scanf("%d%d%d", &a, &b, &c);
maps[a][b] = maps[b][a] = max(maps[a][b], c);
}
ans = INF;
Dij(, n);
printf("Scenario #%d:\n", t++);
printf("%d\n\n", ans);
}
return ;
}
Heavy Transportation---poj1797的更多相关文章
- (最短路) Heavy Transportation --POJ--1797
链接: http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K To ...
- POJ--1797 Heavy Transportation (最短路)
题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...
- POJ1797 Heavy Transportation 【Dijkstra】
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 21037 Accepted: ...
- (Dijkstra) POJ1797 Heavy Transportation
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 53170 Accepted: ...
- POJ1797:Heavy Transportation(改造Dijkstra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 52728 Accepted: ...
- POJ1797 Heavy Transportation —— 最短路变形
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- Heavy Transportation(最短路 + dp)
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
随机推荐
- Hbase 管理页面
进入Hbase首页可以查看各种信息: http://192.168.23.128:16010/master-status
- C语言的声明的优先级规则
C语言的声明的优先级规则如下: A 声明从它的名字开始读取,然后按照优先级顺序依次读取 B 优先级从高到低依次是: B.1 声明中被括号括起来的那一部分 B.2 后缀操作符[圆括号 ()表示这 ...
- Ansible 远程执行脚本
1. 先在服务端创建一个 shell 脚本 [root@localhost ~]$ cat /tmp/test.sh #!/bin/bash echo "hello world" ...
- 在RDLC报表中对纸张的设置
RDLC报表是存放成XML文件格式的,这一点你可以直接打开RDLC报表文件看一下,而且在使用时,通过ReportViewer来读取报表并与数据源进行合成,也就是说RDLC是定义了一个格式,那就不能通过 ...
- css 去除页面双击事件
-ms-touch-action: manipulation !important;
- 【调试错误】找不到 System.Web.Mvc 引用
今天调试新项目,从svn上clone下来,发现运行不了. System.Web.Mvc 显示黄色叹号 解决方案如下: 安装一个 MVC 的插件.AspNetMVC2_VS2008.exe 下载地址:h ...
- JSON语法介绍
官网:https://www.json.org/ JSON (JavaScript Object Notation) is a lightweight data-interchange f ...
- Eclipse的控制台console经常闪现
Eclipse的控制台console有时候经常闪现! 让它不经常的调出来,可以按下面的操作去掉它: windows -> preferences -> run/debug ...
- MyBatis学习之多表查询
一对多需求:即一张表class中又含有多张表(teacher,student)内容.现根据class_id 来获取对应的班级信息(包括学生和老师信息) 方式一:嵌套结果 使用嵌套结果映射来处理重复的联 ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十:PS/2模块④ — 普通鼠标
实验十:PS/2模块④ - 普通鼠标 学习PS/2键盘以后,接下来就要学习 PS/2 鼠标.PS/2鼠标相较PS/2键盘,驱动难度稍微高了一点点,因为FPGA(从机)不仅仅是从PS/2鼠标哪里读取数据 ...