#include <bits/stdc++.h>
using namespace std;
const int MAXM=4040,INF=0x3f3f3f3f;
inline int read(){
int x=0,f=1;char c=getchar();
while (!isdigit(c)){if (c=='-') f=-1;c=getchar();}
while (isdigit(c)){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*f;
}
struct Edge{
int from,to,dist;
Edge(int u,int v,int d):from(u),to(v),dist(d){}
};
struct HeapNode{
int d,u;
bool operator <(const HeapNode& rhs)const{
return d>rhs.d;
}
};
struct Dijkstra{
int n,m;
vector<Edge> edges;
vector<int> G[MAXM];
int d[MAXM];
void init(int n){
this->n=n;
for (int i=0;i<=n;i++) G[i].clear();
edges.clear();
}
void AddEdge(int from,int to,int dist){
edges.push_back(Edge(from,to,dist));
m=edges.size();
G[from].push_back(m-1);
}
void dijkstra(int s){
priority_queue<HeapNode> Q;
for (int i=0;i<=n;i++) d[i]=INF;
d[s]=0;Q.push((HeapNode){0,s});
while (!Q.empty()){
HeapNode x=Q.top();Q.pop();
int u=x.u;
if (x.d!=d[u]) continue;
for (int i=0;i<G[u].size();i++){
Edge& e=edges[G[u][i]];
if (d[e.to]>d[u]+e.dist){
d[e.to]=d[u]+e.dist;
Q.push((HeapNode){d[e.to],e.to});
}
}
}
}
}Dij;
int n,m,A,B,C,S,T;
struct node{
int u,v,l,r;
}a[MAXM];
int main(){
freopen("route.in","r",stdin);freopen("route.out","w",stdout);
n=read(),m=read(),A=read(),B=read(),C=read();
for (int i=1;i<=m;i++) a[i].u=read(),a[i].v=read(),a[i].l=read(),a[i].r=read();
Dij.init(m+1);S=0,T=m+1;
for (int i=1;i<=m;i++)
for (int j=1;j<=m;j++){
if (i!=j&&a[i].v==a[j].u&&a[j].l>=a[i].r)Dij.AddEdge(i,j,A*(a[j].l-a[i].r)*(a[j].l-a[i].r)+B*(a[j].l-a[i].r)+C);
}
for (int i=1;i<=m;i++)
if (a[i].u==1) Dij.AddEdge(S,i,A*a[i].l*a[i].l+B*a[i].l+C);
for (int i=1;i<=m;i++)
if (a[i].v==n) Dij.AddEdge(i,T,a[i].r);
Dij.dijkstra(S);
printf("%d\n",Dij.d[T]);
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 67.77 us | 140 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 75.03 us | 140 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 75.57 us | 140 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 68.69 us | 140 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 22.745 ms | 10 MB + 548 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 13.741 ms | 4 MB + 804 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 27.196 ms | 11 MB + 908 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 18.228 ms | 9 MB + 316 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 28.85 ms | 19 MB + 112 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 12.495 ms | 3 MB + 124 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 34.702 ms | 20 MB + 208 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 21.696 ms | 10 MB + 236 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 25.116 ms | 11 MB + 436 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 31.787 ms | 18 MB + 240 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 615.6 us | 204 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #16 | 619.04 us | 204 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #17 | 647.39 us | 204 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 617.63 us | 204 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 615.57 us | 204 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 653.07 us | 204 KB | Runtime Error | Score: 0 | 显示更多 |