POJ - 1797 Heavy Transportation

1.题面

http://poj.org/problem?id=1797

2.题意

不想说,心累

3.思路

像dijkstra搞一搞,堆优化

4.代码

/*****************************************************************
    > File Name: Cpp_Acm.cpp
    > Author: Uncle_Sugar
    > Mail: uncle_sugar@qq.com
    > Created Time: 2016年07月13日 星期三 14时31分07秒
*****************************************************************/
# include <iostream>
# include <queue>
using namespace std;

const int size  = 100000 + 10; 
const int INF = INT_MAX>>1;

int n,m;
struct edge{
	int to,w;
	edge(){}
	edge(int _to,int _w):to(_to),w(_w){}
};
struct d{
	int w,no;
	d(){}
	d(int _w,int _no):w(_w),no(_no){};
	bool operator < (const d& cmper)const {
		return w<cmper.w; 
	}
};
int dist[size];
vector<edge> g[size];
priority_queue<d> pri_que;
int main()
{
	std::ios::sync_with_stdio(false);cin.tie(0);
	int i,j;
	int T;
	cin >> T;
	for (int cas=1;cas<=T;cas++){
		cin >> n >> m;
		while (!pri_que.empty()) pri_que.pop();
		for (i=1;i<=n;i++) {
			dist[i] = 0; g[i].clear();
		}
		while (m--){
			int a,b,c;
			cin >> a >> b >> c;
			g[a].push_back(edge(b,c));
			g[b].push_back(edge(a,c));
		}
		dist[1] = INF;
		pri_que.push(d(INF,1));
		while (!pri_que.empty()){
			d T = pri_que.top();pri_que.pop();	
			if (dist[T.no] > T.w) continue;
			for (i=0;i<g[T.no].size();i++){
				int to = g[T.no][i].to;
				int w  = g[T.no][i].w;
				if (min(w,dist[T.no]) > dist[to]){
					dist[to] = min(w,dist[T.no]);
					pri_que.push(d(dist[to],to));
				}
			}
		}
		cout << "Scenario #" << cas << ":" << endl;
		cout << dist[n] << endl << endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值