14pts 求助
查看原帖
14pts 求助
1115392
small_moon楼主2024/7/24 14:43
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef pair<int,int> PII;
struct Edge{
	int v,ed,next;
}eg[N*4];
int read();
int n,m,K,S,P,Q,tot;
int v[N],nbs[N],dis[N];
void add(int x,int y)
{
	tot++; eg[tot].ed=y; eg[tot].next=nbs[x]; nbs[x]=tot;
}
void bfs(int s)
{
	queue <PII> q;
	q.push(make_pair(s,0));
	while(!q.empty())
	{
		PII k=q.front(); q.pop();
		for(int x=nbs[k.first];x;x=eg[x].next)
		{
			int u=eg[x].ed;
			if(k.second+1<=S && !v[u])
			{
				v[u]=Q;
				q.push(make_pair(u,k.second+1));
			}
		}
	}
}
void dijstra()
{
	priority_queue <PII,vector<PII>,greater<PII> > q;
	memset(dis,0x3f,sizeof dis);
	q.push(make_pair(0,1)); dis[1]=0;
	while(!q.empty())
	{
		PII k=q.top(); q.pop();
		if(k.first>dis[k.second]) continue;
		for(int x=nbs[k.second];x;x=eg[x].next)
		{
			int u=eg[x].ed;
			if(k.first+eg[x].v<dis[u])
			{
				dis[u]=k.first+eg[x].v;
				q.push(make_pair(dis[u],u));
			}
		}
	}
}
int main()
{
	n=read(); m=read(); K=read(); S=read();
	P=read(); Q=read();
	for(int i=1;i<=K;i++)
	{
		int x=read();
		v[x]=1e9;
	}
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		add(x,y); add(y,x);
	}
	for(int i=1;i<=n;i++)
		if(v[i]==1e9) bfs(i);
	for(int i=1;i<=n;i++)
		if(!v[i] && i!=n && i!=1) v[i]=P;
	for(int k=1;k<=n;k++)
		for(int x=nbs[k];x;x=eg[x].next)
			eg[x].v=v[k]+v[eg[x].ed];
	dijstra();
	cout<<dis[n]/2;
	return 0;
}
int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
2024/7/24 14:43
加载中...