比赛 2025暑期集训第5场图论专场 评测结果 AAAAAAAAAA
题目名称 Milk Pumping 最终得分 100
用户昵称 李奇文 运行时间 0.132 s
代码语言 C++ 内存使用 3.68 MiB
提交时间 2025-07-09 11:28:29
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=2005000;
int d[N],n,m,hd[N],tot,ans;
bool vis[N];
struct tu{
	int v,w,nxt,f;
}e[N];
struct node{
	int ds,ps;
	bool operator<(const node &x) const{
		return x.ds<ds;
	}
};
priority_queue<node> q;
void add(int x,int y,int z,int f){
	e[++tot].v=y;
	e[tot].w=z;
	e[tot].f=f;
	e[tot].nxt=hd[x];
	hd[x]=tot;
}
void dijkstra(){
	for(int i=1;i<=1000;i++){
		for(int j=1;j<=n;j++){
			d[j]=1000000009,vis[j]=0;
		}
		d[1]=0;
		q.push({0,1});
		while(!q.empty()){
			node k=q.top();
			q.pop();
			int u=k.ps;
			if(vis[u]) continue;
			vis[u]=1;
			for(int j=hd[u];j;j=e[j].nxt){
				if(e[j].f<i) continue;
				int v=e[j].v,w=e[j].w;
				if(d[v]>d[u]+w){
					d[v]=d[u]+w;
					if(!vis[v]){
						q.push({d[v],v});
					}
				}
			}
		}
		if(d[n]!=1000000009){
			ans=max(ans,i*1000000/d[n]);
		}
	}
}
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,f;
		cin>>a>>b>>c>>f;
		add(a,b,c,f);
		add(b,a,c,f);
	}
	dijkstra();
	cout<<ans<<endl;
	return 0;
}