比赛 2025暑期集训第5场图论专场 评测结果 AAAAAAAAAA
题目名称 Milk Pumping 最终得分 100
用户昵称 KKZH 运行时间 0.052 s
代码语言 C++ 内存使用 5.23 MiB
提交时间 2025-07-09 10:24:34
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=4e5;
int n,m,c,cnt,tot,u;
int head[N],dis[N],f[N],mon[N];
struct node1{
	int num;
	double len;
	friend bool operator<(const node1 a,const node1 b){
		return a.len<b.len;
	}
};
priority_queue <node1> q;
struct node{
	int next,to,len,cost;
}ed[N];
void add(int x,int y,int z,int w){
	ed[++cnt].next=head[x];
	ed[cnt].to=y;
	ed[cnt].cost=z;
	ed[cnt].len=w;
	head[x]=cnt;
}
void dij(){
	dis[1]=0;
	mon[1]=0;
	q.push({1,0});
	while(!q.empty()){
		int x=q.top().num;
		++tot;
		q.pop();
		for(int i=head[x];i!=-1;i=ed[i].next){
			int y=ed[i].to,z=ed[i].len,w=ed[i].cost;
			if(tot!=1) u=min(dis[x],z);
			else u=z;
			if(1.0*dis[y]/mon[y]<1.0*u/(mon[x]+w)){
				dis[y]=u;
				mon[y]=mon[x]+w;
				q.push({y,1.0*dis[y]/mon[y]});
			}
		}
	}
}
int main(){
	freopen("pump.in","r",stdin);
	freopen("pump.out","w",stdout);
	memset(head,-1,sizeof(head));
	cin>>n>>m;
	for(int i=0;i<=n;i++) mon[i]=1;
	int x,y,z,w;
	for(int i=1;i<=m;i++){
		cin>>x>>y>>z>>w;
		add(x,y,z,w);
		add(y,x,z,w);
	}
	dij();
	double ans=1.0*dis[n]/mon[n];
	ans*=1e6*1.0;
	cout<<(int)ans<<endl;
	return 0;
}