#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100010,maxm=1000010,maxt=40010;
const ll inf=1145141919810000000ll;
int n,m;ll a,b,c;
struct edge{
int x,y;ll p,q;
}e[maxm];
vector<int>jc[maxn];
int l[maxn];
vector<int>in[maxt],out[maxt];//cal the value when the side in
//join the jc when the side out
ll f[maxm];
ll ans=inf;
inline ll calc(int i,int j){
return f[j]+a*(e[i].p-e[j].q)*(e[i].p-e[j].q)+b*(e[i].p-e[j].q)+c;
}
inline ll getk(int i){
return 2*a*e[i].p+b;
}
inline ll gety(int j){
return f[j]+a*e[j].q*e[j].q;
}
inline ll getx(int j){
return e[j].q;
}
inline int jcn(int pos,int h){
return jc[pos][h];
}
int main(){
ll maxx=0;
ios::sync_with_stdio(false);
cin>>n>>m>>a>>b>>c;
for(int i=1;i<=m;i++){
cin>>e[i].x>>e[i].y>>e[i].p>>e[i].q;
in[e[i].p].push_back(i);
maxx=max(maxx,e[i].q);
//out[e[i].q].push_back(i);
f[i]=inf;
}
jc[1].push_back(0);f[0]=0;
for(int t=0;t<maxx;t++){
for(int i:out[t]){
//join the jc
//#define jcn(h) (jc[e[i].y][h])
int pp=e[i].y;
#define r (((int)jc[e[i].y].size())-1)
int see=r;
#define L (l[e[i].y])
while(L<r&& (1.0*(gety(jcn(pp,r))-gety(jcn(pp,r-1))))/(1.0*(getx(jcn(pp,r))-getx(jcn(pp,r-1))))>=(1.0*(gety(i)-gety(jcn(pp,r))))/(1.0*(getx(i)-getx(jcn(pp,r)))) )jc[e[i].y].pop_back();
jc[e[i].y].push_back(i);
//#undef jcn
#undef r
#undef L
}
for(int i:in[t]){
if(!jc[e[i].x].size())continue;
//cal the ans
//#define jcn(h) (jc[e[i].x][h])
int pp=e[i].x;
#define r (((int)jc[e[i].x].size())-1)
#define L (l[e[i].x])
while( L<r && (1.0*(gety(jcn(pp,L+1))-gety(jcn(pp,L)))) / (1.0*(getx(jcn(pp,L+1))-getx(jcn(pp,L)))) <= (1.0*(getk(i))) )L++;
f[i]=calc(i,jcn(pp,L));
if(e[i].y==n){
ans=min(ans,f[i]+e[i].q);
}
out[e[i].q].push_back(i);
//#undef jcn
#undef r
#undef L
}
}
cout<<ans;
return 0;
}
应该是斜率优化部分炸了,原版题目A了,加强版WA on 1,2,3,5