洛谷 P3063 【[USACO12DEC]Milk Routing S】

这道题可以暴力哒~


我们枚举每一个出现过的容量,然后跑一次最短路,求延迟,在跑最短路的时候,如果遇到的某一个点,比我们当前枚举的那个点小,那么就直接不走这一个点,然后枚举完后,就能得到最大值了。

代码~

#include <bits/stdc++.h>
using namespace std;
struct node{
	int w , v;
};
int n , m , need , ans = 0x3fffffff;
int h[510] , vis[510] , dis[510];
vector<pair<int , node> > e[510];
void work(int minn){
	priority_queue<pair<int , int> > q;
	dis[1] = 0;
	q.push(make_pair(0 , 1));
	while(!q.empty()){
		int x = q.top().second;
		q.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(int i = 0; i < e[x].size(); i++){
			int nx = e[x][i].first , nw = e[x][i].second.w , nv = e[x][i].second.v;
			if(nv < minn) continue;	//不满足的话就下一个 
			if(dis[nx] > dis[x] + nw){
				dis[nx] = dis[x] + nw;
				q.push(make_pair(-dis[nx] , nx));
			}
		}
	}
}
int main(){
	cin >> n >> m >> need;
	for(int i = 1; i <= m; i++){
		int a , b , c , d;
		cin >> a >> b >> c >> d;
		h[i] = d;	//记录下出现过的流量 
		e[a].push_back(make_pair(b , (node){c , d}));
		e[b].push_back(make_pair(a , (node){c , d}));
	}
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++) vis[j] = 0 , dis[j] = 0x3fffffff;	//初始化一下 
		work(h[i]);	//一个个枚举 
		ans = min(ans , dis[n] + need / h[i]);	//记得加上流量 
	}
	cout << ans;
	return 0;
}

三倍经验:

P5837

P1462 这道题要加个二分,其他的都差不多啦

posted @ 2020-06-29 15:56  那一条变阻器  阅读(83)  评论(0编辑  收藏  举报