#include #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll ILL=2167167167167167167; const int INF=2100000000; const ll mod=998244353; #define rep(i,a) for (ll i=0;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";} template void vec_out(vector &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout< dijkstra(vector> &G,int start,len_type inf){ int M=G.size(); assert(M>start&&start>=0); vector seen(M,inf); seen[start]=0; priority_queue,vector>,greater>> pq; pq.push({0,start}); while(!pq.empty()){ len_type time; int ver; tie(time,ver)=pq.top(); pq.pop(); if(seen[ver]>t; rep(i,t) solve(); } void solve(){ int N,M; cin>>N>>M; vector> G(N); rep(i,M){ int a,b; cin>>a>>b; a--,b--; G[a].push_back(b); G[b].push_back(a); } vector> p(2,vector(N)); rep(i,2) rep(j,N){ cin>>p[i][j]; } vector seen(N,-1); seen[0]=0; queue q; q.push(0); int J=0; while(J==0&&!q.empty()){ int a=q.front(); q.pop(); for(auto x:G[a]){ if(seen[x]==-1){ seen[x]=(seen[a]^1); q.push(x); }else if(seen[x]==seen[a]){ J=1; break; } } } if(J==0){ ll A=0,B=0; rep(i,N){ A+=p[seen[i]][i]; B+=p[seen[i]^1][i]; } cout<> H(N*2); rep(j,N){ for(auto x:G[j]){ H[j].push_back({x+N,max(0ll,p[1][j]-p[0][j])}); H[j+N].push_back({x,max(0ll,p[0][j]-p[1][j])}); } } rep(j,N){ auto x=dijkstra(H,j,ILL); chmin(tmp,x[j+N]); x=dijkstra(H,j+N,ILL); chmin(tmp,x[j]); } cout<