#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,A,B,C,cnt=0;
struct Thing{
int x,y,p,q;
bool operator <(const Thing yy) const {
return p<yy.p;
}
}a[200005];
vector<int> rl[200005],id[200005];
long long f[200005],ans=0x3f3f3f3f3f3f3f3fll;
int F(int x){
return A*x*x+B*x+C;
}
int main() {
cin>>n>>m>>A>>B>>C;
for(int i=1;i<=m;i++){
scanf("%d%d%d%d",&a[i].x,&a[i].y,&a[i].p,&a[i].q);
rl[a[i].y].push_back(a[i].q);
}
rl[1].push_back(0);
for(int i=1;i<=n;i++){
sort(rl[i].begin(),rl[i].end());
int tmp=unique(rl[i].begin(),rl[i].end())-rl[i].begin();
rl[i].resize(tmp);
}
for(int i=1;i<=n;i++){
for(int j=0;j<rl[i].size();j++){
id[i].push_back(++cnt);
}
}
memset(f,0x3f,sizeof(f));
f[1]=0;
sort(a+1,a+m+1);
for(int i=1;i<=m;i++){
int fr=a[i].x,to=a[i].y,now;
for(int j=0;j<rl[to].size();j++)if(rl[to][j]==a[i].q)now=id[to][j];
for(int j=0;j<rl[fr].size();j++){
if(rl[fr][j]>a[i].p)break;
int ps=id[fr][j];
f[now]=min(f[now],f[ps]+F(a[i].p-rl[fr][j]));
}
}
for(int i=0;i<rl[n].size();i++){
ans=min(ans,f[id[n][i]]+rl[n][i]);
}
printf("%lld\n",ans);
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.787 ms | 10 MB + 748 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 1.782 ms | 10 MB + 748 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 1.776 ms | 10 MB + 744 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 1.787 ms | 10 MB + 744 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 3.755 ms | 10 MB + 892 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 3.05 ms | 10 MB + 904 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 3.828 ms | 10 MB + 896 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 3.247 ms | 10 MB + 904 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 3.837 ms | 10 MB + 896 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 3.017 ms | 10 MB + 908 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 4.264 ms | 10 MB + 900 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 3.737 ms | 10 MB + 912 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 3.948 ms | 10 MB + 908 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 4.119 ms | 10 MB + 904 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 166.396 ms | 18 MB + 548 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 144.104 ms | 18 MB + 752 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 166.231 ms | 18 MB + 548 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 142.642 ms | 18 MB + 764 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 162.625 ms | 18 MB + 576 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 142.898 ms | 18 MB + 768 KB | Accepted | Score: 5 | 显示更多 |