10 pts 求助,悬 2 关
查看原帖
10 pts 求助,悬 2 关
807774
_Wind_Leaves_ShaDow_楼主2024/6/2 14:22

一天了真的调不出来了,有没有路过的好心的佬帮帮忙 qwq。

记录

#include <bits/stdc++.h>
//#define int long long
#define Rg register
#define Ri Rg int
#define Il inline
#define vec vector
#define pb push_back
#define fi first
#define se second
#define IT ::iterator

using namespace std;

typedef double db;
typedef pair<int,int> pii;
const int N=5e3,M=2e5,Inf=1e9;
const db eps=1e-8;

int n,m,fad[N+5],dss[N+5],ans=1,ey[M+5];
db K,dis[N+5];
bool vis[N+5];

struct Node{
	int to,id;
	db w;
};
vector<Node>vg[N+5],vt[N+5];

struct Nodj{
	int ps;
	db ds;
	Il bool operator <(const Nodj &stmp)const{
		return ds>stmp.ds;	
	}
};
priority_queue<Nodj>dj;

Il void Dijk(){
	dj.push({n,0});
	for(Ri i=1;i<n;i++)dis[i]=Inf;
	while(!dj.empty()){
		int fq=dj.top().ps;
		dj.pop();
		if(vis[fq])continue;
		vis[fq]=1;
		for(Rg Node i:vt[fq]){
			if(dis[fq]+i.w-dis[i.to]>eps)continue;
			dis[i.to]=dis[fq]+i.w;
			fad[i.to]=i.id;
			dj.push({i.to,dis[i.to]});
		}
	}
	return;
}

Il bool cmp(int x,int y){
	return dis[x]<dis[y];
}

struct Heap{
	int ls,rs,dis,fat;
	db w;
}hp[M*18+5];

int idp=0,rt[N+5];

Il int build(int fa,db w){
	hp[++idp]={0,0,0,fa,w};
	return idp;
}

Il int merge(int x,int y){
	if(!x||!y)return x|y;
	if(hp[x].w-hp[y].w>eps)swap(x,y);
	hp[++idp]=hp[x];
	hp[idp].rs=merge(hp[idp].rs,y);
	if(hp[hp[idp].ls].dis<hp[hp[idp].rs].dis)swap(hp[idp].ls,hp[idp].rs);
	hp[idp].dis=hp[hp[idp].ls].dis+1;
	return idp;
}

signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>K;
	for(Ri i=1;i<=m;i++){
		int x;
		db w;
		cin>>x>>ey[i]>>w;
		if(x==n){
			i--;
			m--;
			continue;
		}
		vg[x].pb({ey[i],i,w});
		vt[ey[i]].pb({x,i,w});
	}
	Dijk();
	K-=dis[1];
	for(Ri i=1;i<=n;i++)dss[i]=i;
	sort(dss+1,dss+n+1,cmp);
	for(Ri i=1;i<=n;i++){
		int p=dss[i];
		for(Rg Node j:vg[p])if(fad[p]^j.id)rt[p]=merge(rt[p],build(j.to,j.w+dis[j.to]-dis[p]));
		rt[p]=merge(rt[p],rt[ey[fad[p]]]);
	}
	if(rt[1])dj.push({rt[1],hp[rt[1]].w});
	while(!dj.empty()){
		Nodj fq=dj.top();
		dj.pop();
		if(fq.ds+dis[1]>K)break;
		cout<<K<<'\n';
		K-=fq.ds+dis[1];
		ans++;
		if(hp[fq.ps].ls)dj.push({hp[fq.ps].ls,fq.ds-hp[fq.ps].w+hp[hp[fq.ps].ls].w});
		if(hp[fq.ps].rs)dj.push({hp[fq.ps].rs,fq.ds-hp[fq.ps].w+hp[hp[fq.ps].rs].w});
		if(rt[hp[fq.ps].fat])dj.push({rt[hp[fq.ps].fat],fq.ds+hp[hp[fq.ps].fat].w});
	}
	cout<<ans;
	return 0;
}
2024/6/2 14:22
加载中...