QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301292#5054. City Brainzzuqy#WA 2685ms102064kbC++142.4kb2024-01-09 17:21:282024-01-09 17:21:29

Judging History

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

  • [2024-01-09 17:21:29]
  • 评测
  • 测评结果:WA
  • 用时:2685ms
  • 内存:102064kb
  • [2024-01-09 17:21:28]
  • 提交

answer

#include <bits/stdc++.h>
#define N 5009
using namespace std;
vector<int>to[N];
int n, m, k;
int d[N][N];

void bfs(int st) {
	queue<int>q;
	q.push(st);
	d[st][st] = 0;
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (auto y : to[x]) {
			if (d[st][y] != 1000000000)
				continue;
			d[st][y] = d[st][x] + 1;
			q.push(y);
		}
	}
}

double calc(int a, int b, int kt) {
	if (a == 0 && b == 0)
		return 0;
	kt += a + b;
	if (b == 0)
		return 1.0 * (kt % a) / (kt / a + 1) + 1.0 * (a - kt % a) / (kt / a);
	if (a == 0)
		return 2.0 * (kt % b) / (kt / b + 1) + 2.0 * (b - kt % b) / (kt / b);
	double ans = 1000000000;
	for (int ta = 1; ta <= (kt - b) / a; ta++) {
		int tb = (kt - ta * a) / b;
		assert(tb >= 1 && a * ta + b * tb <= kt);
		//cout << ta << " " << ta << endl;
		double tmp = 1.0 * a / ta + 2.0 * b / tb;
		{
			if (kt - a * ta - b * tb >= a)
				continue;
			ans = min(ans, tmp - (kt - a * ta - b * tb) * 1.0 / ta / (ta + 1));
		}
		{
			if (kt - a * ta - b * tb >= b)
				continue;
			ans = min(ans, tmp - (kt - a * ta - b * tb) * 2.0 / tb / (tb + 1));
			//flag |= 2;
		}
		if (tmp < ans)
			ans = tmp;
	}
	//cout << 1.0 * mntb / mnta << endl;
	return ans;
}
int mn[N];

int main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	fill(d[0], d[0] + N * N, 1000000000);
	for (int i = 1; i <= n; i++)
		bfs(i);
	/*
	for (int i = 1; i <= n; i++, cout << endl)
		for (int j = 1; j <= n; j++)
			cout << d[i][j] << " ";
	*/
	int s1, t1, s2, t2;
	cin >> s1 >> t1 >> s2 >> t2;
	fill(mn, mn + N, 1000000000);
	mn[0] = d[s1][t1] + d[s2][t2];
	for (int a = 1; a <= n; a++) {
		for (int b = 1; b <= n; b++) {
			if (d[s1][a] == 1000000000 || d[b][t1] == 1000000000 || d[a][b] == 1000000000)
				continue;
			if (d[s2][a] == 1000000000 || d[b][t2] == 1000000000)
				continue;
			mn[d[a][b]] = min(mn[d[a][b]], d[s1][a] + d[b][t1] + d[s2][a] + d[b][t2]);
			mn[d[a][b]] = min(mn[d[a][b]], d[s1][a] + d[b][t1] + d[s2][b] + d[a][t2]);
		}
	}
	double ans = 1000000000;
	for (int i = 0; i <= n; i++) {
		if (mn[i] == 1000000000)
			continue;
		//0cout << mn[i] << " " << i << " " << calc(mn[i], i, k) << endl;
		ans = min(ans, calc(mn[i], i, k));
	}
	cout << fixed << setprecision(15) << ans;
}
/*
6 5 100000
1 2
3 2
2 4
4 5
4 6
1 5 2 6
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 101856kb

input:

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

output:

5.000000000000000

result:

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

Test #2:

score: 0
Accepted
time: 3ms
memory: 101984kb

input:

1 0 100
1 1 1 1

output:

0.000000000000000

result:

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

Test #3:

score: 0
Accepted
time: 0ms
memory: 101860kb

input:

4 2 3
1 2
3 4
1 2 3 4

output:

0.833333333333333

result:

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

Test #4:

score: 0
Accepted
time: 0ms
memory: 101868kb

input:

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

output:

5.000000000000000

result:

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

Test #5:

score: 0
Accepted
time: 2685ms
memory: 102064kb

input:

5000 4999 1000000000
1 2
1 3
1 4
1 5
6 2
7 3
8 4
9 5
10 6
11 7
12 8
13 9
14 10
15 11
16 12
17 13
18 14
19 15
20 16
21 17
22 18
23 19
24 20
25 21
26 22
27 23
28 24
29 25
30 26
31 27
32 28
33 29
34 30
35 31
36 32
37 33
38 34
39 35
40 36
41 37
42 38
43 39
44 40
45 41
46 42
47 43
48 44
49 45
50 46
51 47...

output:

0.024989876075614

result:

ok found '0.024989876', expected '0.024989876', error '0.000000000'

Test #6:

score: 0
Accepted
time: 2095ms
memory: 101920kb

input:

10 9 305097549
2 1
8 9
6 7
5 4
8 7
4 3
2 3
9 10
6 5
4 3 2 1

output:

0.000000013110561

result:

ok found '0.000000013', expected '0.000000013', error '0.000000000'

Test #7:

score: 0
Accepted
time: 3ms
memory: 101876kb

input:

10 9 9
4 2
3 6
8 6
2 1
7 9
5 2
2 3
10 9
7 4
8 7 9 5

output:

3.833333333333333

result:

ok found '3.833333333', expected '3.833333333', error '0.000000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 101968kb

input:

10 9 19
5 2
4 1
2 1
6 5
10 8
8 1
9 3
7 6
1 3
7 7 6 4

output:

0.700000000000000

result:

ok found '0.700000000', expected '0.700000000', error '0.000000000'

Test #9:

score: -100
Wrong Answer
time: 4ms
memory: 101936kb

input:

100 99 149
82 77
11 14
99 94
29 24
41 31
52 57
64 73
42 32
85 84
88 86
54 59
75 66
38 28
92 90
9 19
60 61
24 19
24 31
21 18
38 47
67 74
79 89
64 66
34 29
23 16
87 83
11 16
2 4
10 11
76 77
36 32
18 22
71 72
79 77
97 96
47 48
43 34
63 55
51 45
91 94
3 1
31 39
41 44
51 58
6 10
48 54
74 76
7 15
18 13
32...

output:

1.815151515151515

result:

wrong answer 1st numbers differ - expected: '1.8059829', found: '1.8151515', error = '0.0050768'