Provicy @ 2020-10-17 15:45:36
RT
//hoho! xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
//#define int long long
#define E (n+m)
#define mk make_pair
using namespace std; const int N=4000010;
inline int read()
{
int s=0, w=1; ri char ch=getchar();
while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
return s*w;
}
int n,m,P,tot,in[N],out[N],id[N];
int head[N],maxE; struct Edge { int nxt,to,rdis; }e[N<<2];
inline void Add(int u,int v,int w) { e[++maxE].nxt=head[u]; head[u]=maxE; e[maxE].to=v; e[maxE].rdis=w; }
#define lc (x<<1)
#define rc (x<<1|1)
void Build(int x,int l,int r)
{
in[x]=++tot, out[x]=++tot;
if(l==r)
{
Add(in[x],out[x],0);
id[l]=x;
return;
}
int mid=(l+r)/2;
Build(lc,l,mid), Build(rc,mid+1,r);
Add(in[x],in[lc],0), Add(in[x],in[rc],0);
Add(out[lc],out[x],0), Add(out[rc],out[x],0);
}
void Upd1(int u,int v,int l,int r,int x,int pre,int k)
{
if(l>=u&&r<=v)
{
Add(out[x],in[pre],k);
return;
}
int mid=(l+r)/2;
if(u<=mid) Upd1(u,v,l,mid,lc,pre,k);
if(v>mid) Upd1(u,v,mid+1,r,rc,pre,k);
}
void Upd2(int u,int v,int l,int r,int x,int pre,int k)
{
if(l>=u&&r<=v)
{
Add(out[pre],in[x],k);
return;
}
int mid=(l+r)/2;
if(u<=mid) Upd2(u,v,l,mid,lc,pre,k);
if(v>mid) Upd2(u,v,mid+1,r,rc,pre,k);
}
#undef lc
#undef rc
int dis[N],book[N];
struct Node { int x,w; inline bool operator < (const Node& a) const { return w>a.w; } };
priority_queue<Node> Q;
signed main()
{
n=read(), m=read(), P=read();
Build(1,1,E);
for(ri int i=1;i<=m;i++)
{
int a,b,c,d;
a=read(), b=read(), c=read(), d=read();
int x=n+i;
Upd1(a,b,1,E,1,id[x],1);
Upd2(c,d,1,E,1,id[x],1);
Upd1(c,d,1,E,1,id[x],1);
Upd2(a,b,1,E,1,id[x],1);
}
memset(dis,0x3f,sizeof(dis));
dis[out[id[P]]]=0, Q.push((Node){out[id[P]],0});
while(!Q.empty())
{
Node now=Q.top(); Q.pop();
int x=now.x;
if(book[x]) continue;
book[x]=1;
for(ri int i=head[x];i;i=e[i].nxt)
{
int v=e[i].to;
if(dis[v]>dis[x]+e[i].rdis)
{
dis[v]=dis[x]+e[i].rdis;
Q.push((Node){v,dis[v]});
}
}
}
for(ri int i=1;i<=n;i++) printf("%d\n",dis[out[id[i]]]/2);
return 0;
}
by Leap_Frog @ 2020-10-17 15:46:56
前排膜拜ZK!
建议重构
by RedreamMer @ 2020-10-17 15:48:39
前排狂暴尛zk!
by guvio @ 2020-10-17 15:50:09
hoho!前排狂暴尛zk!
by DPair @ 2020-10-17 15:56:22
@Provicy
有点没看懂,但感觉是双向边的问题?
by Provicy @ 2020-10-17 15:57:20
@DPair 必然是吧((
by DPair @ 2020-10-17 15:59:11
@Provicy 为什么E是n+m啊
by Provicy @ 2020-10-17 15:59:46
@DPair o,我刚意识到我思博了,现在过了,,