#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>//POJ2263
#include <map>
#include <vector>
#include <cstring>
using namespace std;
const int maxn = 210;
const int maxm = 20000;
int n; int r;
int start, dest; //记录节点编号。
bool vis[maxn];//mark each point;//出队列后标记已经被更新过,如果在此访问不可更新其值则不再入队。
int value[maxn];//保存每个节点当前最大值,初始化为-1; //及时在更新 struct edge {
int from;
int to;
int weight;
}; struct point {
int num; // 队列里面到节点编号。
int w; // 队列里面到,到达此节点到距离。
bool operator < (const point& b) const {
return w < b.w;
}
}; vector<edge> G[maxn];
map<string, int> mymap;
priority_queue<point> Q; int work()
{
edge tmp;
point tmp_point;
int Size = G[start].size();
for(int i = 0; i < Size; i++) { //初始化队列。
tmp = G[start][i];
tmp_point.num = tmp.to;
tmp_point.w = tmp.weight;
Q.push(tmp_point);
value[tmp.to] = tmp.weight;//init value;
// printf("value[%d] = %d\n", tmp.to, tmp.weight);
}
while(!Q.empty())
{
tmp_point = Q.top();
// printf("tmp_point.num = %d, tmp_point.w = %d\n", tmp_point.num, tmp_point.w);
Q.pop();
int len = G[tmp_point.num].size();
for(int i = 0; i < len; i++) {
edge edge_tmp = G[tmp_point.num][i];
if(vis[edge_tmp.to]) { //已经被访问过,只是关心有可能得到解到,并入队。
if(value[edge_tmp.to] < min(edge_tmp.weight, tmp_point.w)) {
value[edge_tmp.to] = min(edge_tmp.weight, tmp_point.w);
point p;
p.num = edge_tmp.to;
p.w = value[edge_tmp.to];
Q.push(p);
}
}
else {//未被访问过。
value[edge_tmp.to] = min(edge_tmp.weight, value[edge_tmp.from]);
point p;
p.num = edge_tmp.to;
p.w = value[edge_tmp.to];
Q.push(p);
}
}
vis[tmp_point.num] = true;
if(tmp_point.num == dest) return tmp_point.w;//get result;
}
return value[n];
} void init() {
while(!Q.empty()) Q.pop();
mymap.clear();
memset(vis, false, sizeof(vis));
for(int i = 0; i <= n; i++) {
value[i] = -1;
}
} int main()
{
int counter = 1;
while(scanf("%d%d", &n, &r)!=EOF) {
init();
int cnt = 1; // 给节点编号。
if(n==0 && r==0) break;
string tmp[2];
int weight;
edge t; //临时变量
map<string, int>::iterator it;
for(int i = 1; i <= r; i++) {
cin >> tmp[0];
cin >> tmp[1];
for(int i = 0; i < 2; i++) {
if(mymap.find(tmp[i])==mymap.end())
mymap[tmp[i]] = cnt++;
}
cin >> weight;
t.from = mymap[tmp[0]];
t.to = mymap[tmp[1]];
t.weight = weight;
G[t.from].push_back(t);
t.from = mymap[tmp[1]];
t.to = mymap[tmp[0]];
G[t.from].push_back(t);
}
cin >> tmp[0] >> tmp[1];
start = mymap[tmp[0]], dest = mymap[tmp[1]];
int res = work();
printf("Scenario #%d\n", counter++);
printf("%d tons\n\n", res);
}
return 0;
}

hdu2263Heavy Cargo的更多相关文章

  1. 使用Cargo实现自动化部署

    Cargo是一组帮助用户操作Web容器的工具,它能帮助用户实现自动化部署,而且它几乎支持所有的Web容器,如Tomcat.JBoss.Jetty和Glassfish.Cargo通过cargo-mave ...

  2. Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.2.3:run (default-cli) on project Maven_WebTest: Execution default-cli of goal org.codehaus.cargo:cargo-maven2-plugin:1.2.3:run failed: C

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  3. cargo failed to finish deploying within the timeout period [120000]

    cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin ...

  4. POJ2263 Heavy Cargo

    Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4004   Accepted: 2124 Descr ...

  5. Loading Cargo

    Loading Cargo "Look Stephen, here's a list of the items that need to be loaded onto the ship. W ...

  6. POJ 2263 Heavy Cargo(Floyd + map)

    Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3768   Accepted: 2013 Descr ...

  7. Jenkins [Error] at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:192)

    Deploying /root/.jenkins/workspace/zgg-crm-pre/target/crm.war to container Tomcat 7.x Remote with co ...

  8. K - Heavy Cargo dijkstar

    来源poj2263 Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lates ...

  9. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem C. Cargo Transportation 暴力

    Problem C. Cargo Transportation 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed ...

随机推荐

  1. C#使用Linq To XML读取XML,Linq生成XML,Linq创建带属性或带节点XML

    using System; using System.Linq; using System.Xml.Linq; namespace Sample2 { class Program { static v ...

  2. 包装类、基本数据类型及String类之间的相互转换

    包装类:8种基本数据类型对应一个类,此类即为包装类 一.基本数据类型 包装类 及String之间的转换 1.基本数据类型转化为包装类:调用包装类的构造器      int i=10;     Inte ...

  3. grep常见操作整理(更新)

    提取邮箱和URL [root@test88 ~]# cat url_email.txt root@gmail.com,http://blog.peter.com,peter@qq.com [root@ ...

  4. Go语言入门之变量声明

    1.使用var关键字声明变量,如果没有初始化,则变量默认为零值. var a string "hello world" 2.根据值自行判定变量类型 3.多变量声明 ,, 4.使用v ...

  5. hdu多校第三场

    Problem D. Euler Function 思路:打表找找规律. #include<bits/stdc++.h> #define LL long long #define fi f ...

  6. php打开错误日志

    ini_set("display_errors", "On"); error_reporting(E_ALL | E_STRICT);

  7. ubuntu16.04安装最新版本的wine

    1.安装源 sudo add-apt-repository ppa:wine/wine-builds sudo apt-get update 2.安装wine sudo apt-get install ...

  8. vue-music 关于Search(搜索页面)-- 搜索结果优化

    搜索结果 列表点击跳转到相应的歌手详情页或者 歌曲页面,通过子路由跳转,和singer 组件一样 在suggest.vue 组件判断如果点击的是歌手,则new 一个歌手对象,通过这个对象的id 属性值 ...

  9. urllib2模块、cookielib模块

    urllib2模块 urllib模块和urllib模块类似,用来打开URL并从中获取数据.与urllib模块不同的是,urllib模块不仅可以使用urlopen() 函数还可以自定义Opener来访问 ...

  10. 【转载】RecyclerView源码解析

    原文地址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0307/4032.html 概述 之前面试的时候经常有人问是否用过Re ...