QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593612#5054. City BrainDaiRuiChen007WA 2ms10348kbC++171.5kb2024-09-27 15:00:312024-09-27 15:00:33

Judging History

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

  • [2024-09-27 15:00:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10348kb
  • [2024-09-27 15:00:31]
  • 提交

answer

#include<bits/stdc++.h>
#define ld long double
#define ll long long
using namespace std;
const int MAXN=5005;
const ll inf=2e18;
int n,m,k;
vector <int> G[MAXN];
struct graph {
	int s,t,d[MAXN];
	bool vis[MAXN];
	bitset <MAXN> f[MAXN];
	vector <int> ord;
	int bfs() {
		queue <int> q;
		memset(d,0x3f,sizeof(d));
		q.push(s),d[s]=0;
		while(q.size()) {
			int u=q.front(); q.pop();
			ord.push_back(u),f[u][u]=1;
			for(int v:G[u]) {
				if(d[v]>d[u]+1) {
					d[v]=d[u]+1,q.push(v),f[v]=f[u];
				} else if(d[v]==d[u]+1) f[v]|=f[u];
			}
		}
		return d[t];
	}
}	X,Y;
ll q1(ll x) {
	ll z=sqrt(x)+10;
	while(z*(z-1)>x) --z;
	return z;
}
ll q2(ll x) {
	ll z=sqrt(2*x)+10;
	while(z*(z-1)/2>x) --z;
	return z;
}
signed main() {
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1,u,v;i<=m;++i) scanf("%d%d",&u,&v),G[u].push_back(v),G[v].push_back(u);
	scanf("%d%d%d%d",&X.s,&X.t,&Y.s,&Y.t);
	int z=0,x=X.bfs(),y=Y.bfs();
	for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) {
		bool fx=X.f[i][X.s]&&X.f[j][i]&&X.f[X.t][j];
		bool fy=Y.f[i][Y.s]&&Y.f[j][i]&&Y.f[Y.t][j];
		if(fx&&fy) z=max(z,X.d[j]-X.d[i]);
	}
	if(!x&&!y&&!z) return puts("0"),0;
	ll l=1,r=inf,p=0;
	while(l<=r) {
		ll mid=(l+r)>>1;
		if((q2(mid)-1)*z+(q1(mid)-1)*(x+y-2*z)<=k) l=mid+1,p=mid;
		else r=mid-1;
	}
	ll s1=q1(p),s2=q2(p),q=k-(s2-1)*z-(s1-1)*(x+y-2*z);
	if((s2+1)*s2/2<(s1+1)*s1) {
		printf("%.16Lf",(ld)(x+y-2*z)/s1+((ld)(z-q)/s2+(ld)q/(s2+1))*2);
	} else {
		printf("%.16Lf",(ld)q/(s1+1)+(ld)(x+y-2*z-q)/s1+(ld)z/s2*2);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10348kb

input:

6 5 1
1 2
3 2
2 4
4 5
4 6
1 5 3 6

output:

5.0000000000000000

result:

ok found '5.000000000', expected '5.000000000', error '0.000000000'

Test #2:

score: 0
Accepted
time: 2ms
memory: 10276kb

input:

1 0 100
1 1 1 1

output:

0

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #3:

score: 0
Accepted
time: 2ms
memory: 10340kb

input:

4 2 3
1 2
3 4
1 2 3 4

output:

0.8333333333333333

result:

ok found '0.833333333', expected '0.833333333', error '0.000000000'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 10228kb

input:

6 5 1
1 2
3 2
2 4
4 5
4 6
1 5 6 3

output:

5.5000000000000000

result:

wrong answer 1st numbers differ - expected: '5.0000000', found: '5.5000000', error = '0.1000000'