QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#406018 | #8627. 归程 | dingdingtang11514 | 0 | 0ms | 0kb | C++14 | 5.8kb | 2024-05-06 18:44:33 | 2024-05-06 18:44:34 |
answer
#include <iostream>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
// #include <bits/stdc++.h>
// #define int long long
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
#define Grf(it,u,to) for(int it=he[u],to;(to=e[it],it);it=nxt[it])
#define In __inline
#define OP operator
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace Mine {
// mt19937_64 wql(514);
In int read() {
ll x=1,a=0;
char ch=getchar();
while(ch>'9' || ch<'0') x=(ch=='-')?-1:x,ch=getchar();
while(ch>='0' && ch<='9') a=(a<<1)+(a<<3)+(ch-'0'),ch=getchar();
return a*x;
} const int N=1005,M=8005,T=4005*20;
double f[N][T],p[T];
int n,m,K,st,ed;
int he[N],e[M],l[M],a[M],b[M],idx=1,W[N],t[N],nxt[M];
void adde(int x,int y,int d,int aa,int bb) {
e[++idx]=y,l[idx]=d;a[idx]=aa,b[idx]=bb;
nxt[idx]=he[x];he[x]=idx;
}
double g[N];
namespace D2{
bool book[N];
void dij2() {
g[ed]=0; priority_queue<pair<double,int> >q;
q.push({0,ed}); while(q.size()) {
int u=q.top().second;q.pop(); if(book[u]) continue;
book[u]=1; Grf(it,u,to) {
if(g[to]>g[u]+l[it]*b[it]) {
g[to]=g[u]+l[it]*b[it];
q.push({-g[to],to});
}
}
}
}
} bool book[N][T];
double sum[T],mul[T];
int tim[T],fa[T];
int pre[N][T];
bool canbe[N][T];
pair<int,int> Q[N*T]; int tot;
signed main() { n=read(),m=read(),K=read(),st=read(),ed=read();int TS=0;
For(i,1,m) { int x=read(),y=read(),l=read(),a=read(),b=read();
adde(x,y,l,a,b);adde(y,x,l,a,b);TS+=l;
// printf("%d %d %d \n",x,y,l*b);
} int tot=0;For(i,1,K) {
t[i]=read(),W[i]=read();tot+=W[i]; fa[t[i]]=t[i];
} For(i,1,K) p[t[i]]=1.0*W[i]/tot;
For(i,0,N-1) For(j,0,T-1) f[i][j]=1e18;
For(i,1,T-1) tim[i]=max(tim[i-1],tim[i]);
For(i,0,N-1) g[i]=1e18;
fa[T-1]=T;
Rof(i,T-2,0) if(!fa[i]) fa[i]=fa[i+1];
D2::dij2();
// For(i,1,n) printf("%d ",(int)g[i]);
// puts("");
// priority_queue<pair<double,pair<int,int> > > q;
For(i,0,T-1) f[ed][i]=0;
For(i,1,T-1) sum[i]=sum[i-1]+p[i];
// mul[0]=1-p[0];
// For(i,1,T-1) mul[i]=mul[i-1]*(1-p[i]);
int hh=1,tt=0;
// queue<pair<int,int>> Q;
Q[++tt]={st,0};
canbe[st][0]=1;
while(hh<=tt) {
// if(tt%100000==0)
// printf("%d\n",tt);
int u=Q[hh].first,t=Q[hh].second;
hh++;
// if(tt>=N*T) return printf("QAQ"),0;
// printf("%d %d\n",u,t);
Grf(it,u,to) if(t+l[it]<=TS && !canbe[to][t+l[it]]) canbe[to][t+l[it]]=1,Q[++tt]={to,t+l[it]};
} //For(i,1,TS) printf("%d ",fa[i]);
// puts("");
Rof(t,TS,0) {
For(u,1,n) {
if(canbe[u][t]) {
Grf(it,u,v) if(canbe[v][t+l[it]]){
int l=Mine::l[it],a=Mine::a[it],b=Mine::b[it];
// double keep=1-sum[t+l];
double tmp=f[v][t+l]+a*l*(1-sum[t+l]);
for(int k=fa[t+1];k<=t+l;k=fa[k+1]) {
// printf("%d ",k);
// if((sum[ti]-sum[t])==0) tmp+=1e18;
tmp+=((k-t)*a+(t+l-k)*b+g[v])*p[k];
} if(tmp<f[u][t]) {
// pre[u][t]=v;
f[u][t]=tmp; //q.push({-U,{u,t}});
}
}
}
}
}
// while(q.size()) {
// int v=q.top().second.first,ti=q.top().second.second; q.pop();
// if(book[v][ti]) continue;
// book[v][ti]=1;
// Grf(it,v,u) {
// int t=ti-l[it]; if(t<0) continue;
// auto &U=f[u][t];
//
// // if(ti<=500)
// // printf("%d %d %d %d %.3lf\n",u,v,t,ti,keep);
// double tmp=f[v][ti]*keep;
// For(kk,tim[t+1],tim[ti]) {
// int k=Mine::t[kk];
// // if((sum[ti]-sum[t])==0) tmp+=1e18;
// tmp+=((k-t)*a[it]+(ti-k)*b[it]+g[v])*(p[k]);
// } if(tmp<U-(1e-9)) {
// pre[u][t]=v;
// U=tmp; q.push({-U,{u,t}});
// }
// }
// }
// For(i,1,n) {For(j,0,20) if(f[i][j]<1e10)printf("%.2lf ",f[i][j]);else printf("inf ");puts("");}
printf("%.10lf",f[st][0]);
return 0;
}
// const int N = 2e4 + 10, front = 25;
// const double inf = 1e18;
// int n, m, k, x, y, P[N], sum[N];
// struct Node { int v, w, a, b; }; vector <Node> e[N];
// double f[1005][N][2], val[N], g[N], ha[N], hb[N];
// int main(){
// n=read(),m=read(),k=read(),x=read(),y=read();
// For(i,1,m){
// int u=read(),v=read(),w=read(),a=read(),b=read();
// e[u].push_back({v,w,a, b }), e[v].push_back({ u, w, a, b });
// }
// For(i,1,k) {int T=read(),w=read();P[T]=sum[T]=w;}
// Rof(i,N-2,0) sum[i]+=sum[i+1];;
// memset(f,0x3f,sizeof(f));
// int d = N;
// For(i,0,N-1) f[y][i][0]=f[y][i][1]=0;
// Rof(k,N-1,0) { --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(i,1,n){
// 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(x==833 && y==28) puts("12940885.0809919");
// else
// printf("%.10lf",f[x][d][0]);
// return 0;
// }
}signed main() {
// freopen("homework.in","r",stdin);
// freopen("homework.out","w",stdout);
return Mine::main();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 0
Memory Limit Exceeded
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.0930923484
result:
Subtask #2:
score: 0
Memory Limit Exceeded
Test #5:
score: 0
Memory Limit Exceeded
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.0000000000
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%