QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#85192 | #3100. Meetings 2 | lmeowdn | 0 | 8ms | 27204kb | C++14 | 1.5kb | 2023-03-07 09:27:50 | 2023-03-07 09:28:08 |
Judging History
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],g[N],sz[N],cnt,ans[N],ft[N],rt1,rt2;
vi e[N];
void dfs(int u,int fa) {
d[u]=d[fa]+1, sz[u]=1, ft[u]=fa;
for(int v:e[u]) if(v!=fa) dfs(v,u), sz[u]+=sz[v];
}
signed main() {
n=read();
rep(i,2,n) {
int u=read(), v=read();
e[u].eb(v), e[v].eb(u);
}
dfs(1,0);
rep(i,1,n) if(d[i]>d[rt1]) rt1=i;
d[rt1]=0; dfs(rt1,0);
rep(i,1,n) if(d[i]>d[rt2]) rt2=i;
int x=rt2;
while(x) g[++cnt]=x, a[x]=sz[x], x=ft[x];
per(i,cnt,1) a[g[i]]-=a[g[i-1]];
int l=1,r=cnt,suml=a[g[1]],sumr=a[g[cnt]];
rep(k,1,n) {
if(k%2==1) ans[k]=1;
else {
while(suml<k/2) l++, suml+=a[g[l]];
while(sumr<k/2) r--, sumr+=a[g[r]];
ans[k]=r-l+1;
}
}
rep(i,1,n) printf("%lld\n",ans[i]);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 8ms
memory: 26988kb
input:
1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 4ms
memory: 27012kb
input:
2 2 1
output:
1 2
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 3ms
memory: 27028kb
input:
3 1 3 3 2
output:
1 3 1
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 5ms
memory: 27024kb
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: 0ms
memory: 27204kb
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: -4
Wrong Answer
time: 4ms
memory: 26988kb
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 4 1 4 1 2 1 1 1 1
result:
wrong answer 6th lines differ - expected: '5', found: '4'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%