比赛 2025暑期集训第5场图论专场 评测结果 AAAAAAAAAA
题目名称 Milk Pumping 最终得分 100
用户昵称 Lixj 运行时间 0.142 s
代码语言 C++ 内存使用 3.68 MiB
提交时间 2025-07-09 11:43:53
显示代码纯文本
#include<bits/stdc++.h>
#define inf 1e9
using namespace std;
const int N=2222222;
int n,m,head[N],maxx=-1e9,cnt,dis[N];
bool vis[N];
struct Eg{
	int next,c,f,to;
}edge[N];
struct node{
	int dis,pos;
	bool operator<(const node &x) const {
		return dis>x.dis; 
	}
};
void add(int u, int v, int c, int f){ 
	cnt++;
	edge[cnt].c=c;
	edge[cnt].to=v;
	edge[cnt].next=head[u];
	//edge[cnt].next=head[v];
	edge[cnt].f=f;
	
	head[u]=cnt;
	return;
}
priority_queue<node> q;
void dijkstra(){
	for(int x=1;x<=1001;x++){
		for(int j=1;j<=n;j++){ 
			dis[j]=inf;
			vis[j]=0;
		}
		dis[1]=0; 
		q.push((node) {0,1});
		//cout<<q pu
		while(!q.empty()){
			node tmp=q.top(); 
			q.pop();
			int u=tmp.pos;
			if(vis[u]) 
                continue; 
			vis[u]=1; 
			for (int i=head[u];i;i=edge[i].next){
				if(edge[i].f<x) 
                    continue; 
				int v=edge[i].to; 
				if (dis[u]+edge[i].c<dis[v]){
					dis[v]=dis[u]+edge[i].c;
					
					if(!vis[v]/*&&vis[v]>*/){
						q.push((node) {dis[v], v}); 
						
					}
				}
			}
		}
		if(dis[n]!=inf) {
			maxx=max(maxx,x*1000000/dis[n]); 
		}
	}
	return;
}
int main() {
    freopen("pump.in","r",stdin);
    freopen("pump.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		add(a,b,c,d);
		add(b,a,c,d); 
	}
	dijkstra(); 
	cout<<maxx;
	return 0;
}