QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#224721 | #6638. Treelection | fickle | WA | 153ms | 39780kb | C++20 | 1.9kb | 2023-10-23 11:13:47 | 2023-10-23 11:13:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define SZ(a) (int(a.size()))
typedef long long ll;
typedef double db;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
#define log(...) fprintf(stderr, __VA_ARGS__)
std::mt19937_64 gen(std::chrono::system_clock::now().time_since_epoch().count());
ll get(ll l, ll r) { std::uniform_int_distribution<ll> dist(l, r); return dist(gen); }
const int N = 1000100;
int n, f[N], g[N], sz[N], ans[N], z; vi G[N];
void getf(int f[], int t, int x) {
f[x] = 0;
for(int y : G[x]) {
getf(f, t, y);
f[x] += f[y];
}
f[x] = (x != 1) + max(f[x] - t, 0);
}
void dfs(int x, int faze) {
sz[x] = 1;
for(int y : G[x]) {
dfs(y, faze && g[x] != 0);
sz[x] += sz[y];
}
if(sz[x] - 1 > z) {
ans[x] = 1;
} else if(sz[x] - 1 == z && faze && g[1] == 1 && SZ(G[x]) == sz[x] - 1) {
ans[x] = 1;
} else ans[x] = 0;
}
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) G[i].clear();
for(int i = 2; i <= n; i++) {
int p;
cin >> p;
G[p].pb(i);
}
int lo = 1, hi = n, mid;
while(lo < hi) {
mid = (lo + hi) / 2;
getf(f, mid, 1);
if(f[1] > 0) lo = mid + 1;
else hi = mid;
}
z = lo;
// cout << "z = " << z << '\n';
getf(f, z, 1);
getf(g, z - 1, 1);
// cout << "g[1] = " << g[1] << '\n';
// cout << g[2] << '\n';
dfs(1, 1);
for(int i = 1; i <= n; i++)
cout << ans[i];
cout << '\n';
}
signed main() {
atexit([](){cerr << "time: " << (db)clock()/CLOCKS_PER_SEC << "s\n";});
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int _; cin >> _; for(int cas = 1; cas <= _; cas++) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 33884kb
input:
2 4 1 2 3 5 1 1 2 2
output:
1100 10000
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 153ms
memory: 39780kb
input:
10 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
wrong answer 1st lines differ - expected: '111111111111111111111111111111...0000000000000000000000000000000', found: '111111111111111111111111111111...0000000000000000000000000000000'