QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405962#8627. 归程wxqwq0 0ms0kbC++144.5kb2024-05-06 17:43:542024-05-06 17:43:55

Judging History

你现在查看的是最新测评结果

  • [2024-05-06 17:43:55]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-06 17:43:54]
  • 提交

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=10030,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: 0
Runtime Error

Test #1:

score: 0
Runtime Error

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:


result:


Subtask #2:

score: 0
Runtime Error

Test #5:

score: 0
Runtime Error

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:


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%