QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149048 | #5157. High-quality Tree | LaStataleBlue# | WA | 56ms | 16264kb | C++14 | 1000b | 2023-08-23 23:16:47 | 2023-08-23 23:16:47 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
constexpr int MAXN = 2e5 + 10;
vector<int> sons[MAXN];
int d[MAXN];
int rem[MAXN];
void dfs0(const int n) {
if (d[n] != -1)
return;
const int s0 = sons[n][0];
const int s1 = sons[n][1];
dfs0(s0);
dfs0(s1);
const int d0 = d[s0];
const int d1 = d[s1];
rem[s0] = rem[s1] = min(d0, d1) + 1;
if (d0 == d1)
d[n] = d0 + 1;
else
d[n] = min(d0, d1) + 2;
}
int ans = 0;
void dfs1(int n, int r) {
if (n == 0)
return;
if (r <= 0)
ans++;
for (int s : sons[n])
dfs1(s, min(r - 1, rem[s]));
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0, u, v; i < n - 1; i++) {
scanf("%d %d", &u, &v);
sons[u].push_back(v);
}
for (int i = 1; i <= n; i++)
while (sons[i].size() < 2)
sons[i].push_back(0);
fill(d, d + n + 1, -1);
fill(rem, rem + n + 1, 2 * n);
d[0] = 0;
dfs0(1);
dfs1(1, 2 * n);
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8648kb
input:
6 1 2 1 3 3 4 3 5 5 6
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 2ms
memory: 8576kb
input:
12 1 2 2 3 3 4 3 5 1 6 6 7 7 8 7 9 9 10 6 11 11 12
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 56ms
memory: 16264kb
input:
200000 167246 158246 40931 40296 178588 27974 35171 899 4204 163250 101422 9230 55420 93371 16012 140142 28866 154497 33519 180725 50361 52348 46923 175364 126599 169575 15138 34958 164256 64770 63123 130169 154172 168301 127476 54744 199964 81879 173765 69220 178225 73653 59861 46415 138112 17507 8...
output:
0
result:
wrong answer 1st lines differ - expected: '199998', found: '0'