QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138953#4433. Kitten and Roombackiseki#RE 0ms0kbC++171.9kb2023-08-12 14:56:252023-08-12 14:56:28

Judging History

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

  • [2023-08-12 14:56:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-12 14:56:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        cerr << (f++ ? ", " : "") << *L;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

using llf = double;

constexpr int kN = 1000000;

vector<int> g[kN];
int pa[kN];

void dfs(int u, int f) {
    pa[u] = f;
    for (int v : g[u]) {
        if (v == f)
            continue;
        dfs(v, u);
    }
}

llf v1[kN], v2[kN];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n, c;
        cin >> n >> c;
        for (int i = 1; i < n; ++i) {
            int u, v;
            cin >> u >> v;
            --u, --v;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        dfs(0, -1);
        c -= 1;
        v1[c] = 1;
        llf ans = 0;
        int m;
        cin >> m;
        while (m--) {
            int x;
            cin >> x;

            llf cur = v1[x];
            if (pa[x] != -1) {
                cur += v2[pa[x]];
            }

            v1[x] -= cur;
            v2[x] += cur / g[x].size();
            if (pa[x] != -1) {
                v1[pa[x]] += cur / g[x].size();
            }
            
            ans += cur;
        }
        cout << fixed << setprecision(10) << ans << '\n';

        for (int i = 0; i < n; ++i) {
            g[i].clear();
            v1[i] = v2[i] = 0;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
1000000 315562
969409 917725
324847 719085
524235 603427
576843 433171
75335 238378
266746 487233
80422 95099
594363 96140
858172 261406
958326 466109
233845 350950
863969 345645
689972 81395
395383 27274
93913 208983
523722 380358
108074 172341
130041 692304
737158 383812
752080 33646
154356 6672...

output:


result: