QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#367078 | #3100. Meetings 2 | Rikku_eq | 0 | 4ms | 21592kb | C++14 | 2.4kb | 2024-03-25 17:34:32 | 2024-03-25 17:34:33 |
Judging History
answer
#include <bits/stdc++.h>
#define N 200005
#define mxL 20
using namespace std;
typedef long long ll;
int n, L, lg2[N*2], rec[N], stk[N];
int sz[N], d[N], tI[N], id[N*2], tmr;
int st[N][mxL], stD[N][mxL], p[N][mxL];
vector <int> vec[N], to[N];
void dfs (int u, int fa)
{
sz[u]=1; d[u]=d[fa]+1;
tI[u]=++tmr; id[tmr]=d[u];
p[u][0]=fa;
for (int i=1; i<=L; i++) { p[u][i]=p[p[u][i-1]][i-1]; }
int mx=0;
for (int i=0; i<(int)to[u].size(); i++) {
int v=to[u][i];
if (v==fa) { continue; }
dfs(v, u); sz[u]+=sz[v];
id[++tmr]=d[u];
mx=max(mx, sz[v]);
}
for (int i=mx+1; i<=sz[u]; i++) { vec[i].push_back(u); }
}
inline int mn (int l, int r) { return min(st[l][lg2[r-l+1]], st[r-(1<<lg2[r-l+1])+1][lg2[r-l+1]]); }
inline int mxD (int l, int r) { return max(stD[l][lg2[r-l+1]], stD[r-(1<<lg2[r-l+1])+1][lg2[r-l+1]]); }
int main ()
{
// freopen("0test.in", "r", stdin);
// freopen("0test.out", "w", stdout);
scanf("%d", &n);
L=ceil(log(n*2)/log(2));
for (int i=1; i<n; i++) {
int u, v; scanf("%d %d", &u, &v);
to[u].push_back(v);
to[v].push_back(u);
}
for (int i=2; i<=n*2; i++) { lg2[i]=lg2[i>>1]+1; }
dfs(1, 0);
for (int j=tmr; j>=1; j--) {
st[j][0]=id[j];
for (int k=1; j+(1<<(k-1))<=tmr; k++) {
st[j][k]=min(st[j][k-1], st[j+(1<<(k-1))][k-1]);
}
}
for (int i=1; i<=n; i++) {
if (i&1) { printf("1\n"); continue; }
int t=i/2;
int res=-n-1, ans=0;
int tp=0, len=vec[t].size();
for (int j=len-1; j>=0; j--) {
stD[j][0]=d[vec[t][j]];
for (int k=1; j+(1<<(k-1))<len; k++) {
stD[j][k]=max(stD[j][k-1], stD[j+(1<<(k-1))][k-1]);
}
int u=vec[t][j];
int dep=d[u];
for (int k=L; k>=0; k--) {
if (p[u][k] && sz[p[u][k]]<=n-(i/2)) { u=p[u][k]; }
}
ans=max(ans, dep-d[u]+1);
}
for (int j=1; j<len; j++) {
int u=vec[t][j];
rec[j]=mn(tI[vec[t][j-1]], tI[u]);
while (tp>0 && rec[stk[tp]]>rec[j]) { tp--; }
// (stk[tp], j-1)
res=max(res, mxD(stk[tp], j-1)-rec[j]*2);
ans=max(ans, res+d[u]);
stk[++tp]=j;
}
ans++; printf("%d\n", ans);
}
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: 3ms
memory: 16268kb
input:
1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 4ms
memory: 20352kb
input:
2 2 1
output:
1 2
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 20032kb
input:
3 1 3 3 2
output:
1 3 1
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 19148kb
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: -4
Wrong Answer
time: 3ms
memory: 21592kb
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 2 1 2
result:
wrong answer 12th lines differ - expected: '1', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%