跳到正文

剪贴板

剪贴板 mh1rp17g

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
#define il inline
#define ui unsigned int
#define ll long long
#define ull unsigned ll
#define lll __int128
#define db double
#define ldb long double
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define fir first
#define sec second
#define gc getchar
#define pc putchar
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pct __builtin_popcount
#define mst(a,x) memset(a,x,sizeof a)
#define mcp(a,b) memcpy(a,b,sizeof b)
using namespace std;
const int N=2010,INF=0x3f3f3f3f,MOD=998244353;
const ll INFll=0x3f3f3f3f3f3f3f3f;
il int rd() {int x=0,f=1; char ch=gc(); while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=gc();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc(); return x*f;}
il ll rdll() {ll x=0; int f=1; char ch=gc(); while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=gc();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc(); return x*f;}
il void wr(int x) {if(x==INT_MIN) return printf("-2147483648"),void(); if(x<0) return pc('-'),wr(-x); if(x<10) return pc(x+'0'),void(); wr(x/10),pc(x%10+'0');}
il void wrll(ll x) {if(x==LLONG_MIN) return printf("-9223372036854775808"),void(); if(x<0) return pc('-'),wrll(-x); if(x<10) return pc(x+'0'),void(); wrll(x/10),pc(x%10+'0');}
il void wr(int x,const char *s) {wr(x),printf("%s",s);}
il void wrll(ll x,const char *s) {wrll(x),printf("%s",s);}
il int vmod(int x) {return x>=MOD?x-MOD:x;}
il int vadd(int x,int y) {return vmod(x+y);}
il int vsub(int x,int y) {return vmod(x-y+MOD);}
il int vmul(int x,int y) {return 1ll*x*y%MOD;}
il int qpow(int x,int y) {int r=1; for(;y;y>>=1,x=vmul(x,x)) if(y&1) r=vmul(r,x); return r;}
il void cadd(int &x,int y) {x=vmod(x+y);}
il void csub(int &x,int y) {x=vmod(x-y+MOD);}
il void cmul(int &x,int y) {x=vmul(x,y);}
il void cmax(int &x,int y) {x<y&&(x=y);}
il void cmaxll(ll &x,ll y) {x<y&&(x=y);}
il void cmin(int &x,int y) {x>y&&(x=y);}
il void cminll(ll &x,ll y) {x>y&&(x=y);}
#define pli pair<ll,int>
int n,m,s,t,id,a[N],hd[N];
ll ds[N];
vector<pli> g[N];
struct EDGE {int to,w,ne;} e[N*2];
il void add(int u,int v,int w) {e[++id]={v,w,hd[u]},hd[u]=id;}
void QwQ() {
	n=rd(),m=rd();
	for(int u,v,w;m--;) u=rd(),v=rd(),w=rd(),add(u,v,w);
	for(int i=1;i<=n;i++) a[i]=rd();
	s=rd(),t=rd();
	for(int u=1;u<=n;u++) if(!a[u]) {
		priority_queue<pli> q; q.push({0,u}),mst(ds,0x3f),ds[u]=0;
		while(q.size()) {
			int u=q.top().sec; q.pop();
			for(int i=hd[u],v;i;i=e[i].ne) if(ds[u]+e[i].w<ds[v=e[i].to])
				ds[v]=ds[u]+e[i].w,q.push({-ds[v],v});
		}
		for(int i=1;i<=n;i++) if(!a[i]&&ds[i]<=s&&u!=i) g[u].pb({ds[i],i});
	}
	priority_queue<pli> q; q.push({0,1}),mst(ds,0x3f),ds[1]=0;
	while(q.size()) {
		int u=q.top().sec; q.pop();
		for(auto [w,v]:g[u]) {
			ll nd=ds[u]%(s+t)<=s-w?ds[u]+w:ds[u]/(s+t)*(s+t)+s+t+w;
			if(nd<ds[v]) ds[v]=nd,q.push({-nd,v});
		}
	}
	wrll(ds[n]==INFll?-1:ds[n],"\n");
}
signed main() {
//	freopen("in.in","r",stdin),freopen("out.out","w",stdout);
	int T=1; while(T--) QwQ();
}