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 & ...
随机推荐
- c++的字节对齐
win32平台下的微软C编译器对齐策略: 1)结构体变量的首地址能够被其最宽数据类型成员的大小整除.编译器在为结构体变量开辟空间时,首先找到结构体中最宽的数据类型,然后寻找内存地址能被该数据类型大小整 ...
- 【RF库Collections测试】Log Dictionary 【同log list】
Name:Log DictionarySource:Collections <test library>Arguments:[ dictionary | level=INFO ]Logs ...
- c语言中的内存分配malloc、alloca、calloc、malloc、free、realloc、sbr
C语言跟内存分配方式 (1) 从静态存储区域分配.内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量,static变量. (2) 在栈上创建.在执行函数时,函数内局部变 ...
- 123、 android Retrofit 介绍和使用(转载)
简单使用:http://blog.csdn.net/bitian123/article/details/51899716 http://blog.csdn.net/duanyy1990/article ...
- PHP 二叉树 二叉排序树实现
<?php /** * PHP 二叉树 * @author : xiaojiang 2014-01-01 * */ class Tree { protected $k = null; prote ...
- 五、K3 WISE 开发插件《K3 Wise 群发短信配置开发(一)之短信平台配置》
开发环境:K/3 Wise 13.0 目录 一.创建短信数据库 二.配置短信接口 三.设置帐套关键字 四.查询短信余额 一.创建短信数据库 打开帐套管理: 账号默认为Admin,密码不填: 菜单“系统 ...
- 【大数据系列】hadoop集群的配置
一.hadoop的配置文件分类 1.只读类型的默认文件 core-default.xml hdfs-default.xml mapred-default.xml mapred-que ...
- LeetCode - 637. Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an ...
- ESlint全局变量报错
场景: 在main.js下申明了全局变量: /* eslint no-undef: "error" */ window.vm = new Vue({ el: '#app', rou ...
- LeetCode 24 Swap Nodes in Pairs (交换相邻节点)
题目链接: https://leetcode.com/problems/swap-nodes-in-pairs/?tab=Description Problem: 交换相邻的两个节点 如上 ...