已经快调崩溃了,输出比答案大
非加强版此代码已过
#include<bits/stdc++.h>
#define int long long
#define pt putchar(' ')
#define nl puts("")
#define pi pair<int,int>
#define pb push_back
#define go(it) for(auto &it:as[x])
using namespace std;
const int N=1e6+10;
int n,m,A,B,C,ans=1e16;
int f[N],cnt[N],h[N],t[N];
struct node{int u,v,p,q;}E[N];
vector<int> que[N];
priority_queue<pi,vector<pi>,greater<pi>> wait;
int fr(){
int x=0,flag=1;
char ch=getchar();
while(ch<'0' || ch>'9'){
if(ch=='-') flag=-1;
ch=getchar();
}
while(ch>='0' && ch<='9'){
x=x*10+(ch-'0');
ch=getchar();
}
return x*flag;
}
void fw(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) fw(x/10);
putchar(x%10+'0');
}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int F(int x){return A*x*x+B*x+C;}
int X(int i){return E[i].q;}
int Y(int i){return f[i]+A*E[i].q*E[i].q-B*E[i].q-E[i].q;}
long double slo(int i,int j)
{
if(X(i)==X(j))
{
if(Y(j)>Y(i)) return 1e16;
if(Y(j)<Y(i)) return -1e16;
return 0;
}
return 1.0*(Y(j)-Y(i))/(X(j)-X(i));
}
void ins(int id)
{
int u=E[id].u,v=E[id].v,p=E[id].p,q=E[id].q;
int &hh=h[v],&tt=t[v];
if(!~tt) return void(que[v][++tt]=id);
while(hh<tt && slo(que[v][tt-1],que[v][tt])>=slo(que[v][tt],id)) tt--;
que[v][++tt]=id;
}
void pop(int p)
{
while(wait.size() && wait.top().first<=p)
{
ins(wait.top().second);
wait.pop();
}
}
signed main()
{
n=fr(),m=fr(),A=fr(),B=fr(),C=fr();
for(int i=1;i<=m;i++)
E[i].u=fr(),E[i].v=fr(),E[i].p=fr(),E[i].q=fr(),cnt[E[i].v]++;
for(int i=1;i<=n;i++) que[i].resize(cnt[i]+5);
auto tmp=[&](const node &a,const node &b){return a.p==b.p?a.u<b.u:a.p<b.p;};
sort(E+1,E+1+m,tmp);
memset(t,-1,sizeof t);
memset(f,0x3f,sizeof f);
for(int i=1;i<=m;i++)
{
int u=E[i].u,v=E[i].v,p=E[i].p,q=E[i].q;
pop(p);
if(u==1) f[i]=A*p*p+B*p+C+q,wait.push({E[i].q,i});
else if(h[u]<=t[u])
{
int &hh=h[u],&tt=t[u];
while(hh<tt && slo(que[u][hh],que[u][hh+1])<=2*A*p) hh++;
int j=que[u][h[u]];
f[i]=f[j]+F(p-E[j].q)+q-E[j].q;
wait.push({E[i].q,i});
}
if(v==n) ans=min(ans,f[i]);
}
fw(ans);
return 0;
}