QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184700 | #3100. Meetings 2 | bear0131# | 0 | 2ms | 7960kb | C++20 | 2.8kb | 2023-09-21 08:52:15 | 2024-07-04 02:06:05 |
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const int Mod = 998244353;
const int inv2 = (Mod+1) / 2;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 100;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(ll &a, ll b){ (b>a) ? (a=b) : 0; }
int n;
vi g[200200];
int dept[200200], bel[200200], sz[200200], rt = 0, rtsz = inf;
void dfs(int u, int par){
sz[u] = 1;
int mxsz = 0;
rep(i, (int)g[u].size()){
int t = g[u][i];
if(t == par) continue;
dept[t] = dept[u] + 1;
bel[t] = (par == -1 ? t : bel[u]);
dfs(t, u);
sz[u] += sz[t];
mxsz = max(mxsz, sz[t]);
}
mxsz = max(mxsz, n - sz[u]);
if(mxsz < rtsz) rtsz = mxsz, rt = u;
}
int mxdep[200200], ans[200200];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
rep(i, n-1){
int u, v;
cin >> u >> v;
--u, --v;
g[u].emplace_back(v), g[v].emplace_back(u);
}
dfs(0, -1);
dept[rt] = 0, dfs(rt, -1);
static int ord[200200];
rep(i, n) ord[i] = i;
sort(ord, ord+n, [&](int lh, int rh){ return sz[lh] > sz[rh]; });
int p = n/2, curans = 0;
priority_queue< pii > pq;
pq.emplace(0, -1);
for(int i = 1; i < n; ++i){
int u = ord[i];
while(p > sz[u]) ans[p--] = curans + 1;
while(pq.top().second >= 0 && pq.top().second == bel[u]) pq.pop();
curans = max(curans, dept[u] + pq.top().first);
mxdep[bel[u]] = max(mxdep[bel[u]], dept[u]);
pq.emplace(mxdep[bel[u]], bel[u]);
}
while(p) ans[p--] = curans + 1;
for(int i = 1; i <= n; ++i)
if(i & 1)
cout << "1\n";
else
cout << ans[i/2] << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 1ms
memory: 3632kb
input:
1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 2ms
memory: 7900kb
input:
2 2 1
output:
1 2
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
3 1 3 3 2
output:
1 3 1
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 7672kb
input:
14 12 14 12 9 14 2 12 6 12 7 6 4 3 4 1 4 12 8 13 1 10 12 11 6 6 5
output:
1 7 1 5 1 3 1 3 1 2 1 2 1 2
result:
ok 14 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 5724kb
input:
14 10 14 3 10 14 13 1 3 3 5 3 11 12 14 14 6 11 8 2 3 7 8 9 7 1 4
output:
1 8 1 6 1 5 1 4 1 2 1 1 1 1
result:
ok 14 lines
Test #6:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
14 8 13 13 10 13 7 6 8 5 7 10 4 9 5 12 8 6 2 4 11 5 1 9 3 4 14
output:
1 8 1 6 1 5 1 4 1 2 1 1 1 1
result:
ok 14 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 5856kb
input:
14 9 2 9 8 3 8 14 9 13 3 1 2 5 2 9 6 4 2 4 11 10 6 12 10 7 9
output:
1 7 1 5 1 3 1 2 1 2 1 1 1 1
result:
ok 14 lines
Test #8:
score: 0
Accepted
time: 2ms
memory: 7728kb
input:
15 10 7 15 7 14 7 15 11 6 15 10 8 14 2 4 8 15 1 3 6 4 13 1 9 5 2 8 12
output:
1 8 1 6 1 4 1 4 1 3 1 2 1 1 1
result:
ok 15 lines
Test #9:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
16 11 8 11 10 10 1 11 2 15 8 13 10 9 2 2 4 8 6 2 7 3 7 12 9 6 16 9 14 12 5
output:
1 8 1 6 1 4 1 4 1 2 1 2 1 2 1 2
result:
ok 16 lines
Test #10:
score: 0
Accepted
time: 0ms
memory: 5936kb
input:
16 7 11 16 11 11 6 1 16 1 14 1 3 12 3 14 8 12 10 5 16 6 9 6 4 9 2 15 4 2 13
output:
1 10 1 8 1 6 1 4 1 4 1 4 1 2 1 2
result:
ok 16 lines
Test #11:
score: 0
Accepted
time: 1ms
memory: 5628kb
input:
16 13 3 16 13 16 5 16 8 3 12 11 16 14 8 15 12 3 10 10 2 16 1 6 10 11 9 8 4 1 7
output:
1 7 1 5 1 5 1 3 1 3 1 3 1 2 1 1
result:
ok 16 lines
Test #12:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
16 12 13 13 3 14 3 7 14 9 3 11 13 14 8 2 14 14 6 2 16 4 3 7 5 16 1 9 10 13 15
output:
1 7 1 5 1 4 1 3 1 2 1 2 1 2 1 2
result:
ok 16 lines
Test #13:
score: 0
Accepted
time: 2ms
memory: 7780kb
input:
16 1 7 15 1 8 1 15 12 7 2 1 13 13 14 12 3 3 16 11 3 9 3 10 12 2 5 6 7 9 4
output:
1 9 1 7 1 5 1 5 1 4 1 3 1 3 1 2
result:
ok 16 lines
Test #14:
score: 0
Accepted
time: 1ms
memory: 5628kb
input:
14 8 11 11 5 7 5 7 3 3 12 12 2 2 14 14 6 3 1 9 12 6 13 10 1 4 7
output:
1 10 1 8 1 6 1 4 1 3 1 2 1 1
result:
ok 14 lines
Test #15:
score: 0
Accepted
time: 0ms
memory: 7672kb
input:
14 6 8 9 8 1 9 1 3 3 10 5 10 13 5 11 13 11 12 12 14 7 14 4 7 4 2
output:
1 14 1 12 1 10 1 8 1 6 1 4 1 2
result:
ok 14 lines
Test #16:
score: 0
Accepted
time: 2ms
memory: 7696kb
input:
15 4 7 7 3 15 7 7 14 10 7 7 1 13 7 8 7 7 9 6 7 1 5 4 12 2 3 10 11
output:
1 5 1 3 1 1 1 1 1 1 1 1 1 1 1
result:
ok 15 lines
Test #17:
score: 0
Accepted
time: 1ms
memory: 7960kb
input:
16 14 7 15 14 14 5 14 2 14 12 11 14 13 14 14 10 3 14 14 9 14 16 14 6 1 14 14 8 4 14
output:
1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 16 lines
Test #18:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
16 4 9 9 10 10 6 16 6 4 5 5 14 14 15 5 7 8 14 14 13 11 5 5 12 5 2 5 1 3 5
output:
1 8 1 6 1 5 1 4 1 2 1 1 1 1 1 1
result:
ok 16 lines
Test #19:
score: 0
Accepted
time: 2ms
memory: 7668kb
input:
15 4 15 4 10 1 4 5 4 4 12 14 4 11 4 4 13 13 9 6 9 6 7 2 13 2 8 3 2
output:
1 6 1 4 1 3 1 2 1 2 1 2 1 2 1
result:
ok 15 lines
Test #20:
score: 0
Accepted
time: 0ms
memory: 7668kb
input:
16 1 2 2 5 12 2 2 15 14 2 2 11 6 2 10 2 10 4 13 4 16 13 10 9 9 7 9 3 8 3
output:
1 7 1 5 1 3 1 3 1 2 1 2 1 2 1 2
result:
ok 16 lines
Test #21:
score: -4
Wrong Answer
time: 0ms
memory: 7740kb
input:
15 11 15 15 6 15 12 15 2 15 14 9 15 7 15 13 15 4 1 4 3 13 3 8 13 10 8 5 10
output:
1 6 1 4 1 3 1 2 1 2 1 2 1 2 1
result:
wrong answer 2nd lines differ - expected: '7', found: '6'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%