QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414172 | #3788. Funny Car Racing | ggg | 100 ✓ | 53ms | 4736kb | C++20 | 1.3kb | 2024-05-18 16:18:42 | 2024-05-18 16:18:43 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#define INF 999999999
using namespace std;
typedef pair<int,int> PII;
const int N=5e4+5;
int n,m,l,r;
int e[N],h[305],be[N],en[N],w[N],ne[N],cnt;
int dist[305],vis[305];
void join(int u,int v,int a,int b,int t)
{
e[cnt]=v;
be[cnt]=a;
en[cnt]=b;
w[cnt]=t;
ne[cnt]=h[u];
h[u]=cnt++;
}
int dijkstra()
{
dist[l]=0;
priority_queue<PII,vector<PII>,greater<PII>>p;
p.push({0,l});
while(p.size())
{
PII it=p.top();
p.pop();
int ver=it.second,time=it.first;
if(vis[ver])continue;
vis[ver]=1;
for(int i=h[ver];i!=-1;i=ne[i])
{
int j=e[i];
int Time=0;
if(time%(be[i]+en[i])+w[i]>be[i])
{
Time=time+be[i]+en[i]-time%(be[i]+en[i])+w[i];
}
else Time=time+w[i];
if(dist[j]>Time)
{
dist[j]=Time;
p.push({dist[j],j});
}
}
}
return dist[r];
}
int main()
{
int k=0;
while(scanf("%d %d %d %d",&n,&m,&l,&r)!=EOF)
{
k++;
cnt=0;
int u,v,a,b,t;
memset(h,-1,sizeof(h));
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)dist[i]=INF;
for(int i=1;i<=m;i++)
{
scanf("%d %d %d %d %d",&u,&v,&a,&b,&t);
if(a<t)continue;
join(u,v,a,b,t);
}
printf("Case %d: %d\n",k,dijkstra());
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 53ms
memory: 4736kb
input:
155 9507 117 14 19 18 2 123 1 100 97 4 155 3 121 120 1 140 1 5 8 1 121 1 69 66 2 107 2 151 150 2 190 1 68 69 1 101 1 61 60 2 126 1 124 127 2 160 3 59 55 5 133 4 66 67 1 189 1 94 96 2 108 2 65 63 2 181 2 44 48 1 130 1 28 29 1 180 1 5 6 1 107 1 29 28 1 120 1 142 140 4 152 2 46 45 2 113 1 85 88 6 163 3...
output:
Case 1: 249 Case 2: 1540 Case 3: 1741 Case 4: 191 Case 5: 651 Case 6: 767 Case 7: 204 Case 8: 1016 Case 9: 582 Case 10: 248 Case 11: 323 Case 12: 322 Case 13: 1574 Case 14: 873 Case 15: 199 Case 16: 237 Case 17: 429 Case 18: 613 Case 19: 685 Case 20: 316 Case 21: 291 Case 22: 799 Case 23: 1009 Case ...
result:
ok 27 lines