QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#85196#3100. Meetings 2lmeowdn0 14ms27204kbC++141.6kb2023-03-07 09:50:392023-03-07 09:50:41

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 09:50:41]
  • 评测
  • 测评结果:0
  • 用时:14ms
  • 内存:27204kb
  • [2023-03-07 09:50:39]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
#define sgn(x) ((x)&1?-1:1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef long double ld;

int read() {
    int x=0,w=1; char c=getchar(); 
    while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
    while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
    return x*w;
}

const int N=1e6+9;
int n,a[N],d[N],sz[N],cnt,ans[N],msz[N],rt,tp,g[N],mx[N];
vi e[N];

void dfs(int u,int fa,int tp) {
    sz[u]=1;
    for(int v:e[u]) if(v!=fa) d[v]=d[u]+1, dfs(v,u,tp), sz[u]+=sz[v], msz[u]=max(msz[u],sz[v]);
    msz[u]=max(msz[u],n-sz[u]);
    if(tp&&(!rt||msz[u]<msz[rt])) rt=u;
}
void dfs2(int u,int fa) {
    g[sz[u]]=max(g[sz[u]],d[u]);
    for(int v:e[u]) if(v!=fa) dfs2(v,u);
}

signed main() {
    n=read();
    rep(i,2,n) {
        int u=read(), v=read();
        e[u].eb(v), e[v].eb(u);
    }
    dfs(1,0,1); d[rt]=0;
    dfs(rt,0,0);
    rep(i,1,n) ans[i]=1;
    int msz=0;
    for(int u:e[rt]) {
        rep(i,1,sz[u]) g[i]=0;
        dfs2(u,rt);
        per(i,sz[u],1) g[i]=max(g[i],g[i+1]);
        rep(k,1,min(msz,sz[u])) ans[2*k]=max(ans[2*k],g[k]+mx[k]+1);
        rep(k,1,min(sz[u],n-sz[u])) ans[2*k]=max(ans[2*k],g[k]+1);
        msz=max(sz[u],msz);
        rep(i,1,sz[u]) mx[i]=max(mx[i],g[i]);
    }
    rep(i,1,n) printf("%lld\n",ans[i]);
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 4
Accepted
time: 0ms
memory: 27044kb

input:

1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 14ms
memory: 27084kb

input:

2
2 1

output:

1
2

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 4ms
memory: 26924kb

input:

3
1 3
3 2

output:

1
3
1

result:

ok 3 lines

Test #4:

score: -4
Wrong Answer
time: 13ms
memory: 27204kb

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
8
1
5
1
3
1
3
1
2
1
2
1
2

result:

wrong answer 2nd lines differ - expected: '7', found: '8'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%