QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#695808 | #9532. 长野原龙势流星群 | pei | 0 | 186ms | 16556kb | C++23 | 1.8kb | 2024-10-31 20:50:50 | 2024-10-31 20:50:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define PII pair<int,int>
#define int long long
#define inf INT64_MAX
#define endl '\n'
struct Node {
int siz;
int sum;
int pos;
Node() {}
Node(int siz, int sum, int pos) : siz(siz), sum(sum), pos(pos) {}
friend bool operator<(Node a, Node b) {
return a.sum * b.siz < b.sum * a.siz;
}
};
void solve() {
int n;
cin >> n;
vector<int> p(n + 1), sum(n + 1), siz(n + 1, 1), fa(n + 1);
for (int i = 2, x; i <= n; i++) {
cin >> x;
p[i] = x;
}
priority_queue<Node> q;
for (int i = 1; i <= n; i++) {
fa[i] = i;
cin >> sum[i];
q.push(Node(siz[i], sum[i], i));
}
auto find = [&](auto &&self, int x) {
if (x == fa[x])return x;
return fa[x] = self(self, fa[x]);
};
vector<bool> del(n + 1);
vector<double> ans(n + 1);
while (q.size()) {
int a = q.top().siz;
int b = q.top().sum;
int x = q.top().pos;
q.pop();
if (a != siz[x] || b != sum[x])continue;
del[x] = true;
ans[x] = 1.0 * b / a;
if (x ^ 1) {
int y = find(find, p[x]);
fa[x] = y;
siz[y] += siz[x];
sum[y] += sum[x];
q.push(Node(siz[y], sum[y], y));
}
sum[x] = 0, siz[x] = 0;
}
for (int i = 1; i <= n; i++) {
cout << fixed << setprecision(12) << ans[i] << endl;
}
}
signed main() {
#ifdef ONLINE_JUDGE
#else
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3980kb
input:
2000 1 2 2 4 5 2 3 6 4 2 7 2 8 14 8 12 1 14 4 14 8 18 9 2 7 22 20 22 14 29 28 16 6 21 23 6 21 14 13 9 1 4 18 13 2 39 21 33 18 20 38 27 27 1 49 5 51 3 31 24 10 42 2 44 13 9 35 66 27 60 67 59 29 40 53 2 33 43 26 43 62 16 78 45 14 10 73 69 41 35 25 26 2 70 54 1 54 48 5 36 44 28 90 29 51 51 93 82 95 45 ...
output:
24744.000000000000 887174926.000000000000 881025216.709677457809 912609654.666666626930 872318573.500000000000 831791515.153846144676 867874850.000000000000 892392319.166666626930 836427216.000000000000 869519853.799999952316 693335785.375000000000 925100890.000000000000 994728511.500000000000 95030...
result:
wrong answer 1st numbers differ - expected: '883838885.9230770', found: '24744.0000000', error = '0.9999720'
Subtask #2:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 186ms
memory: 16556kb
input:
200000 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
output:
1812.000000000000 794937150.351351380348 794843085.477611899376 804131414.226415038109 805846267.166666626930 806376230.000000000000 778037203.690476179123 815562308.149999976158 776087995.601265788078 809328819.588235259056 767722826.595375776291 771619640.696969747543 800107654.476923108101 879639...
result:
wrong answer 1st numbers differ - expected: '792545632.4154930', found: '1812.0000000', error = '0.9999977'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%