比赛 |
2022级DP专题练习赛2 |
评测结果 |
AAAWWWWWWW |
题目名称 |
物流运输 |
最终得分 |
30 |
用户昵称 |
遥时_彼方 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2023-02-13 20:28:36 |
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
int x=0;bool flag=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
if(flag) return x;
return ~(x-1);
}
inline void write(int x)
{
if(x<0) {x=~(x-1);putchar('-');}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int gcd(int x,int y)
{
if(!(x%y)) return y;
return gcd(y,x%y);
}
////////////////////////
const int N=1e3+5;
const int E=1e3+5;
int n,m,e;
ll kc;
int hd[N];
struct T
{
ll s;
int ar;
int nx;
}a[E<<1];
int aj;
int d;
struct B
{
int p[N];
int pj;
}b[1005];
int q[N];
ull f[E][E];
inline void ADD(int x,int y,int s)
{
a[++aj].s=s;
a[aj].ar=y;
a[aj].nx=hd[x];
hd[x]=aj;
}
queue<int> c;
int cj[N];
ll dis[N];
ll SPFA()
{
memset(cj,0,sizeof(cj));
c.push(1);
cj[1]=1;
dis[1]=0;
int x;
while(c.size())
{
x=c.front();
cj[x]=0;
c.pop();
for(int i=hd[x];i;i=a[i].nx)
{
if(q[a[i].ar]) continue;
if(dis[a[i].ar]>dis[x]+a[i].s)
{
dis[a[i].ar]=dis[x]+a[i].s;
if(!cj[a[i].ar])
{
c.push(a[i].ar);
cj[a[i].ar]^=1;
}
}
}
}
return dis[m];
}
ull dp[E];
int main()
{
freopen("bzoj_1003.in","r",stdin);
freopen("bzoj_1003.out","w",stdout);
cin>>n>>m>>kc>>e;
int s1,s2,s3;
rep(i,1,e)
{
s1=read(),s2=read(),s3=read();
ADD(s1,s2,s3);
ADD(s2,s1,s3);
}
d=read();
rep(i,1,d)
{
s1=read(),s2=read(),s3=read();
rep(o,s2,s3) b[o].p[++b[o].pj]=s1;
}
memset(f,0x7f,sizeof(f));
for(ll i=1;i<=n;i++)
{
memset(q,0,sizeof(q));
for(ll o=i;o<=n;o++)
{
rep(u,1,b[o].pj) q[b[o].p[u]]=1;
// cout<<"p:"<<i<<" "<<o<<endl;
memset(dis,0x3f,sizeof(dis));
f[i][o]=SPFA()*(o-i+1);
if(!f[i][o]) f[i][o]=f[0][0];
// cout<<i<<" "<<o<<":"<<f[i][o]<<endl;
// rep(u,1,m) cout<<u<<":"<<q[u]<<endl;
}
}
// cout<<"p1\n";
memset(dp,0x7f,sizeof(dp));
rep(i,1,m)
{
dp[i]=f[1][i];
rep(k,1,i-1)
{
dp[i]=min(dp[i],dp[k]+f[k+1][i]+kc);
// cout<<i<<" "<<k<<":"<<dp[i]<<endl;
}
}
cout<<dp[n]<<endl;
return 0;
}