QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64491#4433. Kitten and Roombaabdelrahman001#WA 5280ms105920kbC++202.1kb2022-11-24 22:07:542022-11-24 22:07:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-24 22:07:55]
  • 评测
  • 测评结果:WA
  • 用时:5280ms
  • 内存:105920kb
  • [2022-11-24 22:07:54]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

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

#define ll long long
#define ld long double

const int N = 1e6 + 15, mod = 1e9 + 7;

int n, cat, m;
vector<int> g[N];
int ind[N], in[N], out[N], T = 2, p[N];
vector<int> tour;
void dfs(int node, int par) {
    p[node] = par;
    in[node] = out[node] = tour.size();
    for(auto i : g[node]) {
        if(i != par) {
            ind[i] = out[node] = T++;
            tour.push_back(i);
        }
    }
//    out[node] = tour.size() - 1;
    for(auto i : g[node]) {
        if(i != par)
            dfs(i, node);
    }
}

ld BIT[N];
void add(int i, ld val) {
    for(;i <= n + 10;i += i & -i)
        BIT[i] += val;
}

ld query(int i) {
    ld sum = 0;
    for(;i;i -= i & -i)
        sum += BIT[i];
    return sum;
}

void update(int l, int r, ld val) {
    add(l, val);
    add(r + 1, -val);
}

void init() {
    for(int i = 0;i <= n + 10;i++) {
        g[i].clear();
        BIT[i] = 0;
    }
    tour.clear();
    T = 2;
    tour.push_back(0);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string yes = "TAK", no = "NIE";

    int tt;
    cin >> tt;
    while (tt--) {
        cin >> n >> cat;
        init();
        for(int i = 1;i < n;i++) {
            int u, v;
            cin >> u >> v;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        // update 1
        p[1] = 0;
        tour.push_back(1);
        ind[1] = 1;
        dfs(1, 1);
        update(ind[cat], ind[cat], 1);
        cin >> m;
        ld ans = 0;
        for(int i = 0;i < m;i++) {
            int node;
            cin >> node;
            ld k = g[node].size();
            ld cur = query(ind[node]);
            ans += cur;
            update(in[node], out[node], cur / k);
            if(node != 1)
                update(ind[p[node]], ind[p[node]], cur / k);
            update(ind[node], ind[node], -cur);
        }
        cout << fixed << setprecision(10) << ans << '\n';
    }

    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 5280ms
memory: 105920kb

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:

5.9603923456
6.4387077162

result:

wrong answer 1st numbers differ - expected: '5.60942', found: '5.96039', error = '0.06257'