题目链接:http://codevs.cn/problem/1391/
题目大意:太长了,自己看题吧
不难,代码处理细节有点麻烦,我蒟蒻调了1+小时才出来QwQ
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct Link
{
int s,t,c,next;
}l[50000];
struct qu
{
int x,b;
};
bool b[6000];
int w[6000];
int r[6000];
int g[6000];
int dp[6000][3];
int cnt = 0;
queue<qu> Q;
int value(int x)
{
if(x < 0)
return 0;
return x;
}
int abs(int x)
{
if(x < 0)
return -x;
return x;
}
void Add_Link(int s,int t,int c)
{
l[++cnt].s = s;
l[cnt].t = t;
l[cnt].c = c;
l[cnt].next = g[s];
g[s] = cnt;
}
void update(qu p)
{
int x = p.x;
bool now = p.b;
int q = g[x];
if(now)
{
if(dp[x][0] > dp[x][1] + r[x])
{
dp[x][0] = dp[x][1] + r[x];
Q.push((qu){x,0});
}
while(q)
{
bool k = b[l[q].t]^b[x]^now;
if(k == 0 && dp[l[q].t][1] > dp[x][1] + value(l[q].c + abs(w[l[q].t] - w[x])))
{
dp[l[q].t][1] = dp[x][1] + value(l[q].c + abs(w[l[q].t] - w[x]));
Q.push((qu){l[q].t,1});
}
if(k == 1 && dp[l[q].t][0] > dp[x][1] + l[q].c)
{
dp[l[q].t][0] = dp[x][1] + l[q].c;
Q.push((qu){l[q].t,0});
}
q = l[q].next;
}
}
else
{
if(dp[x][1] > dp[x][0])
{
dp[x][1] = dp[x][0];
Q.push((qu){x,1});
}
while(q)
{
bool k = b[l[q].t]^b[x]^now;
if(k == 1 && dp[l[q].t][0] > dp[x][0] + value(l[q].c - abs(w[l[q].t] - w[x])))
{
dp[l[q].t][0] = dp[x][0] + value(l[q].c - abs(w[l[q].t] - w[x]));
Q.push((qu){l[q].t,0});
}
if(k == 0 && dp[l[q].t][1] > dp[x][0] + l[q].c)
{
dp[l[q].t][1] = dp[x][0] + l[q].c;
Q.push((qu){l[q].t,1});
}
q = l[q].next;
}
}
}
int main()
{
int n,m,s,t,c;
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i ++)
scanf("%d",&b[i]);
for(int i = 1;i <= n;i ++)
scanf("%d",&w[i]);
for(int i = 1;i <= n;i ++)
scanf("%d",&r[i]);
for(int i = 1;i <= m;i ++)
{
scanf("%d%d%d",&s,&t,&c);
Add_Link(s,t,c);
}
memset(dp,63,sizeof(dp));
dp[1][b[1]] = 0;
Q.push((qu){1,b[1]});
while(!Q.empty())
{
qu x = Q.front();
Q.pop();
update(x);
}
cout << min(dp[n][0],dp[n][1]);
return 0;
}