被hack了,求调
查看原帖
被hack了,求调
1129446
nksunhaolan楼主2024/10/19 09:40
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const ll N=1505,M=3e5+5;
ll n,m,st1,ed1,st2,ed2;
ll head[N],head1[N],cnt,cnt1;
ll a,b,v;
ll r[N];
struct nnd {
	ll to,next,w;
}eg[M<<1],eg1[M<<2];
ll dis1[N],dis2[N],dis[N];
bool vis1[N],vis2[N];
void init(){
	for(ll i=1;i<=n;i++)head[i]=head1[i]=-1;
	memset(dis1,0x3f,sizeof(dis1));
	memset(dis2,0x3f,sizeof(dis2));
}
void add(const ll& from,const ll& to,const ll& w){
	eg[cnt].to=to;
	eg[cnt].w=w;
	eg[cnt].next=head[from];
	head[from]=cnt++; 
}
void Add(const ll& from,const ll& to,const ll& w){
	eg1[cnt1].to=to;
	eg1[cnt1].w=w;
	eg1[cnt1].next=head1[from];
	head1[from]=cnt1++; 
}
struct node{
	ll to;ll w;
	bool operator > (const node& x) const {return w > x.w ;}
};
priority_queue< node , vector < node > , greater <node> > q;
struct mmb{
	ll from,w;
}; 
vector<mmb> C1[N],C2[N];

map<pair<ll,ll>,bool> mp;

void djs(){
	//第一轮:st1->ed1 
	q.push({st1,0ll});
	dis1[st1]=0ll;
	while(!q.empty()){
		node p=q.top();q.pop();
		if(vis1[p.to])continue;
		else vis1[p.to]=1;
		for(ll i=head[p.to];i!=-1;i=eg[i].next){
			ll to=eg[i].to,w=eg[i].w;
			if(dis1[to]>dis1[p.to]+w){
				dis1[to]=dis1[p.to]+w;
				q.push({to,dis1[to]});
			}
			if(dis1[to]==dis1[p.to]+w){
				C1[to].push_back({p.to,w});
			}
		}
	}
	//第二轮 st2->ed2
	q.push({st2,0ll});
	dis2[st2]=0ll;
	while(!q.empty()){
		node p=q.top();q.pop();
		if(vis2[p.to])continue;
		else vis2[p.to]=1;
		for(ll i=head[p.to];i!=-1;i=eg[i].next){
			ll to=eg[i].to,w=eg[i].w;
			if(dis2[to]>dis2[p.to]+w){
				dis2[to]=dis2[p.to]+w;
				q.push({to,dis2[to]});
			}
			if(dis2[to]==dis2[p.to]+w){
				C2[to].push_back({p.to,w});
			}
		}
	}
	memset(vis1,0,sizeof(vis1));
	memset(vis2,0,sizeof(vis2));
	queue<ll>p;
	p.push(ed2);
	while(!p.empty()){
		ll x=p.front();p.pop();
		for(ll i=0;i<C2[x].size();i++){
			ll from=C2[x][i].from;
			ll w=C2[x][i].w;
			if(dis2[from]+w==dis2[x]){
				mp[make_pair(from,x)]=1; 
				if(!vis2[from]){
					vis2[from]=1;
					p.push(from);
				}
			}
		}
	}
	p.push(ed1);
	while(!p.empty()){
		ll x=p.front();p.pop();
		for(ll i=0ll;i<C1[x].size();i++){
			ll from=C1[x][i].from;
			ll w=C1[x][i].w;
			if(dis1[from]+w==dis1[x]){
				r[x]++;
				if(mp[make_pair(from,x)] || mp[make_pair(x,from)]){
					Add(from,x,w);
				} else {
					Add(from,x,0ll);
				}
				if(!vis1[from]){
					vis1[from]=1;
					p.push(from);
				}
			}
		}
	}
	p.push(st1);
	while(!p.empty()){
		ll x=p.front();p.pop();
		for(ll i=head1[x];i!=-1;i=eg1[i].next){
			ll to=eg1[i].to;ll w=eg1[i].w;
			r[to]--;
			dis[to]=max(dis[to],dis[x]+w);
			if(r[to]==0)p.push(to);
		} 
	}
	cout<<dis[ed1];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin>>n>>m;init();
	cin>>st1>>ed1>>st2>>ed2;
	for(ll i=1;i<=m;i++){
		cin>>a>>b>>v;
		add(a,b,v);
		add(b,a,v);
	}
	djs();
	return 0ll;
}
2024/10/19 09:40
加载中...