#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=1e5+1,M=2e5+1,T=1e3+1;
int n,m,A,B,C,f[N][T];
struct Edge {
int u,v,p,q;
bool operator < (const Edge &rhs) const {
return p<rhs.p;
}
};
Edge e[M];
inline int calc(const int &x) {
return A*x*x+B*x+C;
}
inline void upd(int &a,const int &b) {
a=std::min(a,b);
}
int main() {
n=getint(),m=getint();
A=getint(),B=getint(),C=getint();
for(register int i=1;i<=m;i++) {
const int u=getint(),v=getint(),p=getint(),q=getint();
e[i]=(Edge){u,v,p,q};
}
for(register int i=1;i<=n;i++) {
std::fill(&f[i][0],&f[i][T],INT_MAX);
}
f[1][0]=0;
std::sort(&e[1],&e[m]+1);
for(register int i=1;i<=m;i++) {
for(register int j=0;j<=e[i].p;j++) {
if(f[e[i].u][j]==INT_MAX) continue;
upd(f[e[i].v][e[i].q],f[e[i].u][j]+calc(e[i].p-j));
}
}
int ans=INT_MAX;
for(register int i=0;i<T;i++) {
if(f[n][i]!=INT_MAX) upd(ans,f[n][i]+i);
}
printf("%d\n",ans);
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 90.7 us | 412 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 89.75 us | 412 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 65.74 us | 272 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 63.37 us | 264 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 2.504 ms | 7 MB + 720 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 2.539 ms | 7 MB + 712 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 2.527 ms | 7 MB + 712 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 2.538 ms | 7 MB + 732 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 2.52 ms | 7 MB + 704 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 2.468 ms | 7 MB + 700 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 2.503 ms | 7 MB + 724 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 2.553 ms | 7 MB + 728 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 2.529 ms | 7 MB + 724 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 2.546 ms | 7 MB + 724 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 143.7 ms | 384 MB + 908 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 144.651 ms | 384 MB + 936 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 140.496 ms | 384 MB + 928 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 139.097 ms | 384 MB + 920 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 150.939 ms | 384 MB + 920 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 140.833 ms | 384 MB + 928 KB | Accepted | Score: 5 | 显示更多 |