QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#587042#5054. City BrainhcywoiWA 0ms3968kbC++232.7kb2024-09-24 17:15:062024-09-24 17:15:07

Judging History

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

  • [2024-09-24 17:15:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3968kb
  • [2024-09-24 17:15:06]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m, k;
    std::cin >> n >> m >> k;

    std::vector<std::vector<int>> adj(n);
    for (int i = 0; i < m; i ++ ) {
        int u, v;
        std::cin >> u >> v;
        u --, v -- ;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int s1, t1, s2, t2;
    std::cin >> s1 >> t1 >> s2 >> t2;
    s1 --, t1 --, s2 --, t2 -- ;

    std::vector dis(n, std::vector<int>(n, -1));
    for (int i = 0; i < n; i ++ ) {
        std::queue<int> q;
        q.push(i);
        dis[i][i] = 0;
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            for (auto y : adj[x]) {
                if (dis[i][y] == -1) {
                    dis[i][y] = dis[i][x] + 1;
                    q.push(y);
                }
            }
        }
    }

    double ans;

    int d0 = dis[s1][t1], d1 = dis[s2][t2];
    if (d0 + d1 == 0) {
        ans = 0;
    } else {
        int t = k / (d0 + d1);
        int rmain = k % (d0 + d1);
        ans = 1. / (t + 1) * (d0 + d1 - rmain) + 1. / (t + 2) * rmain;
    }

    for (int s = 0; s < n; s ++ ) {
        for (int t = s + 1; t < n; t ++ ) {
            if (dis[s][t] == -1 || dis[s1][s] == -1 || dis[t][t1] == -1 || dis[s2][s] == -1 || dis[t][t2] == -1) {
                continue;
            }
            int both = dis[s][t];
            int dis1 = dis[s1][s] + dis[t][t1];
            int dis2 = dis[s2][s] + dis[t][t2];

            auto f = [&](int x) {
                if (x * both > k) {
                    return 1E9;
                }
                int nk = k;
                double res = 2. / (x + 1) * both;
                nk -= x * both;
                if (dis1 + dis2 > 0) {
                    int t = nk / (dis1 + dis2);
                    res += 1. / (t + 1) * (dis1 + dis2);
                    nk -= t * (dis1 + dis2);
                    if (nk > 0) {
                        if (std::min(both - 1, nk) * 2. / (x + 1) / (x + 2) > nk * 1. / (t + 1) / (t + 2)) {
                            res -= std::min(both - 1, nk) * 2. / (x + 1) / (x + 2);
                        } else {
                            res -= nk * 1. / (t + 1) / (t + 2);
                        }
                    }
                } else {
                    res -= std::min(both - 1, nk) * 2. / (x + 1) / (x + 2);
                }
                return res;
            };

            for (int i = 0; i <= k; i ++ ) {
                ans = std::min(ans, f(i));
            }
        }
    }
    std::cout << std::fixed << std::setprecision(9) << ans << "\n";

    return 0;
}

详细

Test #1:

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

input:

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

output:

5.000000000

result:

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

Test #2:

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

input:

1 0 100
1 1 1 1

output:

0.000000000

result:

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

Test #3:

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

input:

4 2 3
1 2
3 4
1 2 3 4

output:

0.833333333

result:

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

Test #4:

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

input:

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

output:

5.500000000

result:

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