#include<cstdio>
#include<cstring>
#include<iostream>
#define ui unsigned int
const ui inf=2100000000;
using namespace std;
struct node{
int next,to,p,q;
}w[200001];
ui f[1005][100001],A,B,C,ans;
int n,m,t,cnt,head[100001];
inline int calc(int x){return A*x*x+B*x+C;}
inline void add(int x,int y,int p,int q){
w[++cnt].next=head[x];
w[cnt].to=y; head[x]=cnt;
w[cnt].p=p; w[cnt].q=q;
}
int main(){
int x,y,p,q;
scanf("%d%d%u%u%u",&n,&m,&A,&B,&C);
for (int i=1; i<=m; i++){
scanf("%d%d%d%d",&x,&y,&p,&q);
add(x,y,p,q); t=max(t,q);
}
for(int i=0 ;i<=t; i++)
for(int j=0; j<=n; j++)
f[i][j]=inf;
f[0][1]=0;
for(int i=0; i<=t; i++)
for(int j=1; j<=n; j++){
if(f[i][j]==f[0][0]) continue;
for (int k=head[j]; k; k=w[k].next){
if (w[k].p<i) continue;
f[w[k].q][w[k].to]=min(f[w[k].q][w[k].to],f[i][j]+calc(w[k].p-i));
}
}
ans=f[0][0];
for(int i=0; i<=t; i++) ans=min(ans,f[i][n]+i);
printf("%u\n",ans);
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 246.22 us | 2 MB + 228 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 238.22 us | 2 MB + 52 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 399.85 us | 4 MB + 148 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 410.56 us | 4 MB + 204 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 2.794 ms | 10 MB + 408 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 2.819 ms | 10 MB + 412 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 2.895 ms | 10 MB + 400 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 2.859 ms | 10 MB + 308 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 2.795 ms | 10 MB + 356 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 2.732 ms | 10 MB + 340 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 2.845 ms | 10 MB + 432 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 3.416 ms | 10 MB + 460 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 2.94 ms | 10 MB + 360 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 3.316 ms | 10 MB + 360 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 296.373 ms | 346 MB + 424 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 266.468 ms | 346 MB + 424 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 211.736 ms | 345 MB + 668 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 121.791 ms | 346 MB + 424 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 402.141 ms | 346 MB + 424 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 135.381 ms | 346 MB + 424 KB | Accepted | Score: 5 | 显示更多 |