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 & ...
随机推荐
- RAC的搭建(一)--安装环境准备
软硬件环境准备: 1.1 虚拟环境: VirtualBox上两个虚拟机,3G内存1核 1.2 软件环境: 数据库安装软件:p10404530_112030_LINUX_1of7.zip p10404 ...
- js数组sort方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 《C++ Primer Plus》16.2 智能指针模板类
智能指针是行为类似于指针的类对象,单这种对象还有其他功能.本节介绍三个可帮助管理动态内存分配的智能指针类.先来看看需要哪些功能以及这些功能是如何实现的.请看下面的函数:void remodel(std ...
- VC下遍历文件夹中的所有文件的几种方法
一.使用::FindFirstFile和::FindNextFile方法 #include "StdAfx.h" #include <windows.h> #inclu ...
- 查询SQlServer相同表结构差异
USE [数据库名] GO ); ); ); ); SET @DataName1='库1'; SET @DataName2='库2'; SET @TableName1='表1'; SET @Table ...
- QSS样式表之PS黑色风格+白色风格+淡蓝色风格(开源)
用QUI皮肤生成器制作皮肤,基本上不超过一分钟就可以生成一套自己想要的皮肤,只要设置八种颜色即可.本人非常喜欢这套黑色风格样式皮肤,特意分享出来,下载地址:https://download.csdn. ...
- 【大数据系列】hadoop脚本分析
一.start-all.sh hadoop安装目录/home/hadoop/hadoop-2.8.0/ libexec/hadoop-config.sh ---设置变量 sbin/start- ...
- AD采样模块采集带模拟量真空表值的实验
实验采用带模拟量,分辨率为1-5V,量程为0--101kpa的真空表 数据采集模块采用DAM-8021, 16位模块 算法描述如下: 真空表读数范围: 0到-101kpa 模拟量输出: 1-5V 一 ...
- Android 编译时:m、mm、mmm、mma、mmma的区别
m:编译整个安卓系统 makes from the top of the tree mm:编译当前目录下的模块,当前目录下需要有Android.mk这个makefile文件,否则就往上找最近的Andr ...
- div里粘贴文字后,移动光标至最后
cursormanager.js //Namespace management idea from http://enterprisejquery.com/2010/10/how-good-c-hab ...