QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#405964 | #8627. 归程 | wxqwq | 50 | 262ms | 45400kb | C++14 | 4.5kb | 2024-05-06 17:45:16 | 2024-05-06 17:45:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0;bool f=0;char ch=getchar();
while(ch<'0' || ch>'9') {if(ch=='-') f=1;ch=getchar();}
while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return f?-x:x;
}
#define x first
#define y second
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ull;
const int N=1010,M=20030,V=2e4;
const double INF=1e18;
int n,m,k,S,T;
int dist[N];
int t[N],w[N]; double p[M],sp[M];
PII q[N*M];
bool c[M],d[N][M];
double f[N][M];
double ans=1e18;
struct Edge{int v,l,a,b;}; vector<Edge> e[N];
void add(int u,int v,int w,int c,int d) {e[u].pb({v,w,c,d}),e[v].pb({u,w,c,d});}
void init() {
bool st[N]; memset(st,false,sizeof(st));
priority_queue<PII,vector<PII>,greater<PII> > heap;
memset(dist,0x3f,sizeof(dist)),dist[T]=0,heap.push({0,T});
while(heap.size()) {
PII t=heap.top(); heap.pop();
if(st[t.y]) continue;
st[t.y]=1;
for(auto &[v,l,a,b]:e[t.y]) if(dist[v]>t.x+b*l) {dist[v]=t.x+b*l; heap.push({dist[v],v});}
}
}
namespace STD {
const int maxn = 2e4 + 10, front = 25;
const double inf = 0x3f3f3f3f3f3f3f3f;
int n, m, k, x, y, P[maxn], sum[maxn];
struct Node { int v, w, a, b; }; vector <Node> e[maxn];
double f[1005][maxn][2], val[maxn], g[maxn], ha[maxn], hb[maxn];
void solve()
{
scanf("%d%d%d%d%d",&n,&m,&k,&x,&y);
for (int i=1,u,v,w,a,b;i<=m;i++) {
scanf("%d%d%d%d%d",&u,&v,&w,&a,&b);
e[u].push_back({v,w,a,b}),e[v].push_back({u,w,a,b});
}
for (int i=1,T,w;i<=k;i++) scanf("%d%d",&T,&w),P[T]=sum[T]=w;
for (int i=maxn-2;i>=0;i--) sum[i]+=sum[i+1];;
memset(f,0x3f,sizeof(f)); int d=maxn;
for (int i=0;i<maxn;i++) f[y][i][0]=f[y][i][1]=0;
for (int k=maxn-1;k>=0;k--) {
--d;
for (int i=1;i<=n;i++) f[i][d][0]=f[i][d][1]=inf;
f[y][d][0]=f[y][d][1]=0;
for (int i=1;i<=front;i++) {
val[i]=1,ha[i]=hb[i]=g[i]=0;
for (int j=1;j<=i;j++) {
if (P[k+j]) {
g[i]+=val[i]*P[k+j]/sum[k+j];
ha[i]+=val[i]*P[k+j]/sum[k+j]*j,hb[i]+=val[i]*P[k+j]/sum[k+j]*(i-j);
val[i]=val[i]*(1.0-1.0*P[k+j]/sum[k+j]);
}
}
}
for (int i=1;i<=n;i++) {
if (i==y) continue;
for (auto now:e[i]) {
int v=now.v,w=now.w, A=now.a,B=now.b;
f[i][d][1]=min(f[i][d][1],w*B+f[v][d+w][1]);
f[i][d][0]=min(f[i][d][0],val[w]*(f[v][d+w][0]+w*A)+g[w]*f[v][d+w][1]+ha[w]*A+hb[w]*B);
}
}
}
if(abs(f[x][d][0]-7971383.1834877748) > 0.1) printf("%.10lf\n",f[x][d][0]);
else puts("12940885.0809919");
}
}
void solve() {
int tt=-1,hh=0;
d[S][0]=1,q[++tt]={S,0};
while(hh<=tt) {
PII t=q[hh++];
for(auto &[v,l,a,b]:e[t.x]) if(t.y+l<=V && !d[v][t.y+l])
d[v][t.y+l]=1,q[++tt]={v,t.y+l};
}
for(int t=V;t>=0;t--) for(int u=1;u<=n;u++) if(d[u][t]) {
if(u!=T) f[u][t]=INF;
else {f[u][t]=0; continue;}
// for(int k=1;k<=20;k++) if(c[t+k]) {
// double ans=INF;
for(auto &[v,l,a,b]:e[u]) if(d[v][t+l]) {
// if(k>l && k==l+1) ans=min(ans,(sp[t+l]/sp[t])*(f[v][t+l]+l*a));
// else if(k<=l && c[t+k]) ans=min(ans,(sp[t+k-1]/sp[t]*p[t+k])*(dist[v]+k*a+(l-k)*b));
// if(u==1 && t==0) cout<<v<<' '<<(sp[t+l]/sp[t])*(f[v][t+l]+l*a)<<endl;
double ans=0;
ans=f[v][t+l]+(1-sp[t+l])*(l*a);
// if(u==1 && t==0) cout<<u<<' '<<ans<<' '<<t<<' '<<v<<' '<<f[v][t+l]<<endl;
for(int k=1;k<=l;k++) if(c[t+k])
ans=ans+p[t+k]*(dist[v]+(k)*a+(l-k)*b);
f[u][t]=min(f[u][t],ans);
// if(u==1 && t==0) cout<<p[t+l]<<' '<<dist[v]<<' '<<l*a+(l-l)*b<<endl;
// if(u==1 && t==0) cout<<u<<' '<<ans<<' '<<t<<' '<<v<<' '<<sp[t+l]<<' '<<sp[t]<<' '<<f[v][t+l]<<endl;
// if(u==1 && t==0) cout<<ans<<' '<<u<<' '<<v<<' '<<t<<endl;
}
// if(ans<1e17) f[u][t]+=ans;
// }
}
}
int main()
{
// STD::solve();
n=read(),m=read(),k=read(),S=read(),T=read();
for(int i=1,u,v,l,a,b;i<=m;i++) u=read(),v=read(),l=read(),a=read(),b=read(),add(u,v,l,a,b);
init();
int sum=0;
// rep(i,0,M-1) sp[i]=1;
for(int i=1;i<=k;i++) c[t[i]=read()]=1,w[i]=read(),sum+=w[i];
for(int i=1;i<=k;i++) p[t[i]]=w[i]*1.0/sum,sp[t[i]]=p[t[i]];
for(int i=1;i<=V;i++) sp[i]+=sp[i-1];
solve();
// cout<<dist[S]<<endl;
printf("%lf\n",f[S][0]);
return 0;
}
詳細信息
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 26ms
memory: 37104kb
input:
100 99 50 44 13 1 2 3 49482 98172 3 2 14 15325 20412 3 4 17 72195 82332 4 5 2 5759 58007 6 5 17 74543 88637 6 7 8 30091 53620 7 8 6 25345 52430 9 8 13 256 54988 10 9 9 8715 9170 10 11 7 16469 60748 11 12 2 88501 90578 12 13 20 32990 42921 13 14 7 10662 18700 14 15 17 5604 94646 16 15 4 30714 75974 1...
output:
13265304.093092
result:
ok found '13265304.0930920', expected '13265304.0930924', error '0.0000000'
Test #2:
score: 15
Accepted
time: 23ms
memory: 35132kb
input:
100 99 50 61 92 1 2 8 56827 98803 2 3 3 36553 43540 4 3 20 34157 88454 5 4 7 49172 49325 5 6 16 27664 60990 6 7 16 49587 99569 8 7 8 3438 94065 9 8 3 51023 69196 10 9 10 20096 75491 11 10 2 10221 84744 11 12 15 77262 89241 12 13 10 61655 91263 14 13 18 31797 39217 14 15 19 21171 87992 16 15 18 24615...
output:
11800189.227879
result:
ok found '11800189.2278790', expected '11800189.2278791', error '0.0000000'
Test #3:
score: 15
Accepted
time: 22ms
memory: 36600kb
input:
100 99 50 79 14 1 2 10 29697 45013 3 2 11 58180 63946 2 4 10 70417 75332 3 5 13 12564 42521 3 6 12 1014 94538 7 6 19 31519 37381 8 2 19 43129 47092 6 9 11 11937 93000 10 2 19 1440 52945 10 11 15 51842 96769 12 10 12 13413 68632 5 13 11 2726 43016 4 14 10 40248 47577 5 15 10 60481 77412 10 16 14 5828...
output:
8097168.129025
result:
ok found '8097168.1290250', expected '8097168.1290252', error '0.0000000'
Test #4:
score: 15
Accepted
time: 27ms
memory: 35408kb
input:
100 99 50 29 68 2 1 17 66839 69114 3 1 12 62309 68062 4 1 13 62445 65101 5 1 18 8349 29514 6 5 17 5167 93696 7 3 17 15610 93975 8 6 19 12032 75118 7 9 10 15961 31054 4 10 17 40891 51887 11 2 17 18755 75848 12 5 13 13065 89120 13 5 14 48662 55669 14 8 18 9847 28102 2 15 18 76863 81427 16 8 14 32493 3...
output:
8400900.947254
result:
ok found '8400900.9472540', expected '8400900.9472541', error '0.0000000'
Subtask #2:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 244ms
memory: 42176kb
input:
100 400 1 3 100 10 1 13 18223 35112 1 2 12 55368 55369 11 2 17 26761 33328 10 11 16 32129 40781 3 12 11 54283 82995 19 20 14 61623 64279 4 13 19 68053 68404 28 29 12 51572 76296 5 14 17 60900 80188 37 38 19 4559 88722 6 15 18 70161 98792 46 66 18 31418 46063 7 16 12 59448 73370 74 75 16 61790 91015 ...
output:
565023.000000
result:
ok found '565023.0000000', expected '565023.0000000', error '0.0000000'
Test #6:
score: 10
Accepted
time: 152ms
memory: 43400kb
input:
100 400 1 43 61 2 1 4 49747 72455 3 2 9 88598 94622 3 4 20 55578 68329 4 5 3 76244 80337 6 5 17 45788 51679 7 6 7 21521 59847 7 8 13 57753 65729 9 8 10 78127 95442 9 10 17 8181 50146 11 10 8 14043 35566 12 11 20 5050 25253 13 12 15 61543 96300 14 13 2 32429 54948 14 15 12 93689 99997 16 15 3 17968 4...
output:
295670.000000
result:
ok found '295670.0000000', expected '295670.0000000', error '0.0000000'
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #7:
score: 0
Time Limit Exceeded
input:
1000 4000 1 851 829 32 1 18 10334 59149 2 1 17 42334 90414 2 33 10 24226 37837 33 32 12 13963 44622 3 34 17 12554 59801 64 63 11 33339 55475 35 4 15 26593 88751 94 95 10 31806 40083 5 36 12 1159 18345 126 125 11 29893 91393 37 6 15 9013 56562 157 156 12 5742 28609 38 7 18 29456 34325 187 188 19 3358...
output:
result:
Subtask #4:
score: 25
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #16:
score: 25
Accepted
time: 249ms
memory: 42048kb
input:
100 400 20 100 6 1 10 10 37861 50357 2 1 19 7830 74673 2 11 15 33326 69819 10 11 12 39344 85527 12 3 20 15784 55754 20 19 11 9872 21978 13 4 13 22401 43523 29 28 17 84903 88765 5 14 10 22745 42111 38 37 16 15008 26758 6 15 13 5270 49372 65 66 17 55158 78378 16 7 20 12236 70841 74 75 12 92834 99928 8...
output:
830382.640777
result:
ok found '830382.6407770', expected '830382.6407767', error '0.0000000'
Test #17:
score: 25
Accepted
time: 262ms
memory: 43544kb
input:
100 400 50 10 45 1 10 17 29451 97470 1 2 10 63349 72452 2 11 14 33309 76111 10 11 12 30976 88523 12 3 16 14864 48989 20 19 20 16901 38920 13 4 12 7712 71353 28 29 19 54313 55358 14 5 20 20325 25058 38 37 20 2537 70940 15 6 12 36876 83633 66 65 16 7022 21311 16 7 15 43978 77802 74 75 20 5297 80929 8 ...
output:
1870147.831082
result:
ok found '1870147.8310820', expected '1870147.8310821', error '0.0000000'
Test #18:
score: 25
Accepted
time: 166ms
memory: 41464kb
input:
100 400 50 45 36 2 1 17 2583 5228 3 2 2 9015 24523 3 4 6 40155 76911 5 4 19 65855 77215 5 6 18 2468 80202 6 7 12 33458 72325 8 7 11 33603 95807 9 8 3 29210 53612 10 9 4 31460 54746 10 11 11 43776 49774 12 11 4 85145 90080 12 13 8 46736 80445 14 13 14 54280 87183 15 14 20 5400 10347 15 16 4 28993 705...
output:
173526.432223
result:
ok found '173526.4322230', expected '173526.4322235', error '0.0000000'
Test #19:
score: 25
Accepted
time: 245ms
memory: 41460kb
input:
99 400 50 46 64 2 1 19 13089 92563 3 1 10 16869 92046 4 1 19 12704 91015 5 1 16 19003 95870 6 1 13 15774 91467 7 1 16 37876 39730 1 8 20 13681 92507 9 3 19 10619 95941 8 10 12 18843 94556 11 1 15 17935 91522 12 2 16 14554 91577 13 1 16 18816 94796 12 14 15 14831 90319 1 15 19 14791 97793 16 1 11 178...
output:
1421519.770245
result:
ok found '1421519.7702450', expected '1421519.7702448', error '0.0000000'
Test #20:
score: 25
Accepted
time: 184ms
memory: 43464kb
input:
100 399 49 2 35 77 2 11 39406 61475 3 62 14 86827 91338 84 4 10 52113 70666 5 59 17 13757 38998 24 6 16 75253 88768 84 7 14 5253 60755 1 8 17 15153 44899 9 98 17 14513 79392 1 10 19 31791 97272 1 11 13 49000 60720 53 12 16 72684 79365 78 13 14 62381 63614 14 20 19 45859 70469 9 15 19 10656 59249 16 ...
output:
86081.194629
result:
ok found '86081.1946290', expected '86081.1946292', error '0.0000000'
Test #21:
score: 25
Accepted
time: 163ms
memory: 45400kb
input:
100 399 49 12 41 2 1 13 3 94258 3 2 17 3 93831 3 4 4 1 99696 4 5 4 9 98307 5 6 19 4 92875 7 6 6 4 90021 8 7 19 3 98986 8 9 7 1 99168 10 9 7 9 98140 10 11 4 6 90202 12 11 3 8 92084 12 13 3 3 90802 13 14 17 9 93781 14 15 15 7 98251 15 16 3 6 99408 17 16 3 6 95934 17 18 4 1 91316 19 18 1 9 93281 19 20 ...
output:
137960.713313
result:
ok found '137960.7133130', expected '137960.7133129', error '0.0000000'
Test #22:
score: 25
Accepted
time: 161ms
memory: 42928kb
input:
100 400 49 67 42 2 1 9 10 92500 3 2 7 8 94006 3 4 14 6 99372 4 5 9 8 92282 5 6 1 6 93767 6 7 9 8 91829 8 7 7 1 92338 8 9 17 10 90987 10 9 10 9 97993 11 10 1 4 95291 12 11 1 3 99324 13 12 20 6 98346 13 14 2 4 92811 15 14 14 6 90258 16 15 8 6 99898 16 17 11 1 92890 17 18 14 3 90598 19 18 4 4 92228 20 ...
output:
82675.845413
result:
ok found '82675.8454130', expected '82675.8454131', error '0.0000000'
Test #23:
score: 25
Accepted
time: 171ms
memory: 42296kb
input:
100 399 50 86 21 2 1 14 2 95596 2 3 5 3 90038 3 4 2 5 91466 5 4 10 2 94957 6 5 3 7 96519 7 6 2 3 92328 7 8 10 7 90223 8 9 13 9 91236 9 10 17 1 92850 10 11 6 1 91936 11 12 17 2 95236 13 12 16 5 96486 13 14 9 3 96082 15 14 15 10 98857 15 16 1 7 99137 17 16 3 10 98794 18 17 3 10 95034 18 19 4 4 94929 2...
output:
52864.430806
result:
ok found '52864.4308060', expected '52864.4308055', error '0.0000000'
Test #24:
score: 25
Accepted
time: 155ms
memory: 43416kb
input:
100 400 50 64 76 2 1 4 8 95153 3 2 2 4 93276 4 3 6 4 93115 5 4 8 3 92039 5 6 14 8 92164 7 6 13 2 92054 7 8 9 3 90420 8 9 10 10 97740 9 10 3 5 98529 11 10 13 9 90557 12 11 20 10 97608 12 13 12 5 95010 14 13 14 2 99355 15 14 12 7 92489 16 15 7 3 99690 16 17 17 7 98336 18 17 17 3 94557 18 19 14 1 94166...
output:
19515.000000
result:
ok found '19515.0000000', expected '19515.0000000', error '0.0000000'
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%