#include <bits/stdc++.h>
using namespace std;
struct node
{
int from;
int to;
int from_time;
int to_time;
node()
{
}
node(int _a,int _b,int _c,int _d)
{
from=_a,to=_b,from_time=_c,to_time=_d;
}
}q[200005];
bool cmp(node x,node y)
{
if (x.from_time==y.from_time) return x.to_time<y.to_time;
return x.from_time<y.from_time;
}
int read()
{
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c))
{
if(c=='-')f=1;
c=getchar();
}
while(isdigit(c))
{
x=x*10+c-'0';
c=getchar();
}
if(f)x=-x;
return x;
}
long long n,m,A,B,C,vis[100005][55],sum[100005][55],cnt[100005];
long long ans=1e18;
int main() {
//freopen("route.in","r",stdin);
//freopen("route.out","w",stdout);
memset(vis,0x7fffffffffffffff,sizeof(vis));
memset(sum,0x7fffffffffffffff,sizeof(sum));
vis[1][1]=0;
sum[1][1]=0;
cnt[1]=1;
cin>>n>>m>>A>>B>>C;
for (int i=0;i<m;i++)
{
int a=read(),b=read(),c=read(),d=read();
q[i]=node(a,b,c,d);
}
sort(q,q+m,cmp);
for (int i=0;i<m;i++)
{
long long minn=0x7fffffffffffffff;
for (int j=1;j<=cnt[q[i].from];j++)
{
if (vis[q[i].from][j]>q[i].from_time) continue;
int y=q[i].from_time-vis[q[i].from][j];
minn=min(minn,(long long)sum[q[i].from][j]+(long long)A*y*y+(long long)B*y+C);
}
if (minn!=(long long)0x7fffffffffffffff)
{
sum[q[i].to][++cnt[q[i].to]]=minn;
vis[q[i].to][cnt[q[i].to]]=q[i].to_time;
}
}
for (int i=1;i<=cnt[n];i++)ans=min(ans,sum[n][i]+vis[n][i]);
cout<<ans<<endl;
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 6.988 ms | 83 MB + 996 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 7.025 ms | 83 MB + 996 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 7.031 ms | 83 MB + 996 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 6.987 ms | 83 MB + 996 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 7.461 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 7.474 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 7.477 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 7.486 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 7.47 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 7.44 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 8.256 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 7.479 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 8.272 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 7.5 ms | 84 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 63.272 ms | 87 MB + 796 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 55.31 ms | 87 MB + 796 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 41.052 ms | 87 MB + 796 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 37.151 ms | 87 MB + 796 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 169.857 ms | 87 MB + 796 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 38.062 ms | 87 MB + 796 KB | Accepted | Score: 5 | 显示更多 |