QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#82397 | #4615. 榕树之心 | hellojim | 20 | 992ms | 16612kb | C++14 | 1.3kb | 2023-02-27 19:25:02 | 2023-02-27 19:25:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int W,T;
int n;
vector<int>g[N];
int sz[N],f[N],dep[N];
int son1[N],son2[N];
int ans[N];
void dfs1(int u,int fa){
dep[u]=dep[fa]+1;
sz[u]=1;
son1[u]=son2[u]=0;
for(auto v:g[u]){
if(v==fa)continue;
dfs1(v,u);
sz[u]+=sz[v];
if(sz[v]>sz[son1[u]]){
son2[u]=son1[u];son1[u]=v;
}
else if(sz[v]>sz[son2[u]]){
son2[u]=v;
}
}
int v=son1[u];
if(sz[v]-2*f[v]<=sz[u]-sz[v]-1)f[u]=(sz[u]-1)/2;
else f[u]=2*f[v]+sz[u]-sz[v]-1;
}
int h;
void dfs2(int u,int fa){
int tmp1=h;
if(!h||sz[son2[u]]>sz[h])h=son2[u];
int tmp2=h;
if(!h||sz[son1[u]]>=sz[h])h=son1[u];
int tmp3=h;
if((n-dep[u])%2==0&&sz[h]-2*f[h]<=n-dep[u]-sz[h])ans[u]=1;
else ans[u]=0;
for(auto v:g[u]){
if(v==fa)continue;
if(v==son1[u])h=tmp2;
else h=tmp3;
dfs2(v,u);
}
h=tmp1;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++)g[i].clear();
for(int i=1;i<n;i++){
int x,y;cin>>x>>y;
g[x].push_back(y);g[y].push_back(x);
}
dfs1(1,0);h=0;
dfs2(1,0);
if(W==3){
cout<<ans[1]<<"\n";
}
else{
for(int i=1;i<=n;i++)cout<<ans[i];cout<<"\n";
}
}
int main(){
// cin.tie(0);cout.tie(0);
// ios::sync_with_stdio(0);
// freopen("move.in","r",stdin);freopen("move.out","w",stdout);
cin>>W>>T;
while(T--)solve();
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 7704kb
input:
1 50 15 1 2 2 3 3 4 2 5 1 6 1 7 7 8 2 9 7 10 4 11 10 12 8 13 5 14 1 15 15 1 2 1 3 1 4 3 5 5 6 6 7 4 8 4 9 2 10 10 11 6 12 10 13 3 14 5 15 15 1 2 2 3 2 4 1 5 2 6 1 7 7 8 8 9 8 10 7 11 4 12 2 13 7 14 1 15 15 1 2 1 3 3 4 3 5 3 6 3 7 6 8 5 9 3 10 10 11 7 12 2 13 8 14 8 15 15 1 2 1 3 2 4 2 5 4 6 1 7 6 8 ...
output:
101010011110000 100010111101010 101101010010110 100111100100011 100110010011000 101011100110000 101011010110101 100101100010111 101110000100111 101010101011100 001011000010110 100110100000101 101100110000010 101110011010101 101110010010100 101010100111010 100100110011000 100110101100011 001100010100...
result:
wrong answer 17th lines differ - expected: '000100010011000', found: '100100110011000'
Subtask #2:
score: 20
Accepted
Test #2:
score: 20
Accepted
time: 992ms
memory: 16612kb
input:
2 20 100000 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52...
output:
010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...
result:
ok 20 lines
Subtask #3:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 9ms
memory: 7428kb
input:
3 200 99 62 2 2 3 2 4 4 5 4 6 5 7 5 8 5 9 9 10 4 11 9 12 12 13 12 14 8 15 14 16 9 17 11 18 5 19 10 20 18 21 2 22 5 23 14 24 5 25 15 26 9 27 1 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 53 54...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '0', found: '1'
Subtask #4:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 8ms
memory: 6512kb
input:
4 20 1000 1 2 2 3 1 4 1 5 2 6 6 7 6 8 6 9 2 10 10 11 5 12 4 13 5 14 5 15 13 16 1 17 2 18 16 19 6 20 13 21 21 22 19 23 11 24 12 25 21 26 7 27 1 28 23 29 3 30 9 31 19 32 1 33 24 34 34 35 35 36 36 37 30 38 22 39 1 40 26 41 34 42 40 43 14 44 6 45 31 46 20 47 16 48 4 49 23 50 7 51 40 52 5 53 29 54 25 55 ...
output:
010110111010000110011010100101011101001110011100000001011011111101110011010111001010011100101010011100001001100000101111100010011111001101110101010100011110110000010011000000001101100101000011100111110111100110101011001111110001111100010110101110110110100100000111100111101000000111010001101010011110...
result:
wrong answer 5th lines differ - expected: '010110010001100010001111011101...0000000000000000000000000000000', found: '010110010001100010001111011101...0101010101010101010101010101010'
Subtask #5:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #4:
0%