wa5 ,HELP
  • 板块CF786B Legacy
  • 楼主paradoxxd
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/7/11 16:16
  • 上次更新2023/10/27 21:04:58
查看原帖
wa5 ,HELP
523864
paradoxxd楼主2022/7/11 16:16
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define push_back emplace_back
#define ull unsigned long long
#define pii pair<long long,int>
/*
 * theFileCreatedAt_2022-07-09_13:21_ *
 * 只有结束的时候才会结束
 */
ll read(){
	ll w=1,q=0;
	char ch=' ';
	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
	if(ch=='-') w=-1,ch=getchar();
	while(ch>='0'&&ch<='9') q=(ll)q*10+ch-'0',ch=getchar();
	return (ll)w*q;
}
const int maxn=1e5+19;
struct xqx{
	struct{
		int nxt,to;
		long long dis;
	}mp[maxn*40];
	int now=0,head[maxn*40];
	void init(int n){
		for(int i=1;i<=n;i++){
			head[i]=0;
		}
		now=0;
	}
	// u-->v
	inline void addedge(int u,int v,long long dis){
		mp[++now].to=v;
		mp[now].nxt=head[u];
		mp[now].dis=dis;
		head[u]=now;
	}
}mp;
int n;
int now;
struct SegTree{
	struct{
		int l,r;
		int id;
	}st[maxn*4];
	int type=0;
	void build(int rt,int l,int r){
		st[rt].l=l,st[rt].r=r;
		if(l==r){
			st[rt].id=l;
			return;
		}
		st[rt].id=++now;
		int m=(l+r)/2;
		build(rt*2,l,m);
		build(rt*2+1,m+1,r);
		if(type==0){
			mp.addedge(st[rt].id,st[rt*2].id,0);
			mp.addedge(st[rt].id,st[rt*2+1].id,0);
		}
		else{
			mp.addedge(st[rt*2].id,st[rt].id,0);
			mp.addedge(st[rt*2+1].id,st[rt].id,0);
		}
	}
	void addedge(int rt,int tgt,int s,int e,long long w){
		int l=st[rt].l,r=st[rt].r;
		if(s<=l&&r<=e){
			if(type==0) mp.addedge(tgt,st[rt].id,w);
			else mp.addedge(st[rt].id,tgt,w);
			return;
		}
		if(e<l||r<s) return;
		addedge(rt*2,tgt,s,e,w);
		addedge(rt*2+1,tgt,s,e,w);
	}
}st1,st2;
long long dis[maxn*40];
int vis[maxn];
priority_queue<pii>pq;
const long long inf=1e18;
void dijk(int start,int size){
	for(int i=1;i<=size;i++)dis[i]=inf;
	for(int i=1;i<=size;i++)vis[i]=0;
	dis[start]=0;
	pq.push(pii(0,start));
	while(!pq.empty()){
		int it=pq.top().second;
		pq.pop();
		if(vis[it])continue;
		vis[it]=1;
		for(int i=mp.head[it];i;i=mp.mp[i].nxt){
			long long di=mp.mp[i].dis;
			int id=mp.mp[i].to;
			if(dis[id]>dis[it]+di){
				dis[id]=dis[it]+di;
				pq.push(pii(dis[id],id));
			}
		}
	}
}
void solve(){
	int q,s;
	cin>>n>>q>>s;
	now=n;
	int t;
	int u,v,l,r;
	long long w;
	st2.type=1;
	st1.build(1,1,n);
	st2.build(1,1,n);
	/*
	if(n==85&&q==100&&s==18){
		cout<<now<<endl;
		for(int i=1;i<=q;i++){
			cin>>t;
			if(t==1){
				cin>>v>>u>>w;
				if(u==1) cout<<t<<v<<' '<<u<<' '<<w<<endl;
			}
			else if(t==2){
				//v->[l,r]
				cin>>v>>l>>r>>w;
				if(l==1) cout<<t<<v<<' '<<l<<' '<<r<<' '<<w<<endl;
			}
			else{
				//[l,r]->v
				cin>>v>>l>>r>>w;
				if(v==1) cout<<t<<v<<' '<<l<<' '<<r<<' '<<w<<endl;
			}
		}
		return;
	}
	*/
	for(int i=1;i<=q;i++){
		cin>>t;
		if(t==1){
			cin>>v>>u>>w;
			mp.addedge(v,u,w);
		}
		else if(t==2){
			//v->[l,r]
			cin>>v>>l>>r>>w;
			st1.addedge(1,v,l,r,w);
		}
		else{
			//[l,r]->v
			cin>>v>>l>>r>>w;
			st2.addedge(1,v,l,r,w);
		}
	}
	dijk(s,now);
	for(int i=1;i<=n;i++)cout<<(dis[i]==inf?-1:dis[i])<<' ';
	cout<<endl;
}
int main(){
	#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#endif
	int t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}
2022/7/11 16:16
加载中...