QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796944#5054. City Brainrlc202204WA 249ms102716kbC++172.7kb2024-12-02 12:05:582024-12-02 12:05:58

Judging History

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

  • [2024-12-02 12:05:58]
  • 评测
  • 测评结果:WA
  • 用时:249ms
  • 内存:102716kb
  • [2024-12-02 12:05:58]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5005;
const int M = 5005;
const int inf = 0x3f3f3f3f;

void read(int &x) {
	x = 0;
	char ch = getchar();
	while (ch > '9' || ch < '0')
		ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
}

int n, m, k;
vector<int> e[N];

int d[2][N] = {{0}};

void bfs(int s, int id) {
	queue<int> q;
	q.push(s), d[id][s] = 0;
	while (!q.empty()) {
		int h = q.front();
		q.pop();
		for (auto i: e[h])
			if (d[id][i] > d[id][h] + 1) {
				d[id][i] = d[id][h] + 1;
				q.push(i);
			}
	}
}

int f[N][N] = {{0}};
int s1, t1, s2, t2;
int dfs(int x, int y) {
	if (f[x][y] != -1)
		return f[x][y];
	if (x == s1 && y == s2)
		return f[x][y] = 0;
	f[x][y] = 0;
	for (auto u: e[x])
		if (d[0][u] + 1 == d[0][x]) {
			f[x][y] = max(f[x][y], dfs(u, y));
			for (auto v: e[y])
				if (d[1][v] + 1 == d[1][y]) {
					f[x][y] = max(f[x][y], dfs(x, v));
					f[x][y] = max(f[x][y], dfs(u, v) + (u == v && x == y));
				}
		}
	return f[x][y];
}

int A[N] = {0}, B[N] = {0};

void upd(int *arr, int len, int val) {
	for (int i = 1; i <= len; i++)
		arr[i] = val;
}

int main() {
	read(n), read(m), read(k);
	for (int i = 1, u, v; i <= m; i++) {
		read(u), read(v); 
		e[u].push_back(v);
		e[v].push_back(u); 
	}
	read(s1), read(t1), read(s2), read(t2);
	memset(d, 0x3f, sizeof d);
	bfs(s1, 0), bfs(s2, 1);
	memset(f, -1, sizeof f);
	int b = dfs(t1, t2);
	int a = d[0][t1] + d[1][t2];
	//也有可能s2,t2倒过来
	swap(s2, t2);
	memset(d, 0x3f, sizeof d);
	memset(f, -1, sizeof f);
	bfs(s1, 0), bfs(s2, 1);
	b = max(b, dfs(t1, t2));
	a -= b * 2;
	//当前有 a 个 1,b 个权值为 2 的 1
	//有 k 次机会
	for (int i = 1; i <= a; i++)
		A[i] = 1;
	for (int i = 1; i <= b; i++)
		B[i] = 1;
	if (a + b == 0) {
		printf("0\n");
	 	return 0;
	}
	if (k <= b) {
		upd(B, k, 2);
	} 
	else {
		k -= b;
		upd(B, b, 2);
		if (k <= a) {
			upd(A, k, 2);
		}
		else {
			k -= a;
			upd(A, a, 2);
			if (k <= b) {
				upd(B, k, 3);
			}
			else {
				k -= b;
				upd(B, b, 3);
				if (k <= b) {
					upd(B, k, 4);
				}
				else {
					k -= b;
					upd(B, b, 4);
					//剩下的是先 a 再 b
					int r = k / (a + b);
					upd(A, a, 2 + r);
					upd(B, b, 4 + r);
					k %= (a + b);
					for (int i = 1; i <= a && k; i++, k--) 
						A[i] = 3 + r; 
					for (int i = 1; i <= b && k; i++, k--)
						B[i] = 5 + r;
				}
			}
		}
	}
	double ans = 0;
	for (int i = 1; i <= a; i++)
		ans += 1.0 / A[i];
	for (int i = 1; i <= b; i++)
		ans += 2.0 / B[i];
	printf("%.11lf\n", ans);
	return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 101928kb

input:

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

output:

5.00000000000

result:

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

Test #2:

score: 0
Accepted
time: 7ms
memory: 101756kb

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: 9ms
memory: 102004kb

input:

4 2 3
1 2
3 4
1 2 3 4

output:

0.83333333333

result:

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

Test #4:

score: 0
Accepted
time: 11ms
memory: 101744kb

input:

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

output:

5.00000000000

result:

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

Test #5:

score: 0
Accepted
time: 249ms
memory: 102716kb

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.02498987608

result:

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

Test #6:

score: 0
Accepted
time: 11ms
memory: 101924kb

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.00000001311

result:

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

Test #7:

score: 0
Accepted
time: 15ms
memory: 101700kb

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.83333333333

result:

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

Test #8:

score: 0
Accepted
time: 7ms
memory: 101748kb

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.70000000000

result:

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

Test #9:

score: -100
Wrong Answer
time: 15ms
memory: 101744kb

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.81515151515

result:

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