QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#880781 | #9983. Color-Balanced Tree | mortis_life | WA | 0ms | 11856kb | C++14 | 1.1kb | 2025-02-03 20:04:14 | 2025-02-03 20:04:15 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+50;
int read() {
int x=0;short f=1;char s=getchar();
while(s<48||s>57){f=s=='-'?-1:1;s=getchar();}
while(s>=48&&s<=57){x=x*10+s-48;s=getchar();}
return x*f;
}
int T,n,siz[2],vis[N];
vector<int> v[N],Q[2];
int fa[N],dep[N];
void dfs(int p,int f) {
fa[p]=f;dep[p]=dep[f]+1;
siz[dep[p]%2]++;
if(p!=1&&v[p].size()==1) Q[dep[p]%2].push_back(p);
for(int i:v[p]) {
if(i==fa[p]) continue;
dfs(i,p);
}
return ;
}
void check() {
cin>>n;
for(int i=1,u,v1;i<n*2;i++) {
u=read(),v1=read();
v[u].push_back(v1),v[v1].push_back(u);
}
dfs(1,0);
int o=0;
if(siz[0]>siz[1]) o++,swap(siz[0],siz[1]),swap(Q[0],Q[1]);
int w=siz[1]-n;
if(w>1&&Q[1].size()<w) cout<<"boom";
else {
for(int i=0;w;i++) {
vis[Q[1][i]]=1;
w--;
}
for(int i=1;i<=n*2;i++) {
if(vis[i]||(dep[i]+o)%2==0) cout<<-1<<" ";
else cout<<1<<" ";
}
}cout<<endl;
}
signed main() {
cin>>T;
while(T--) {
check();
siz[0]=0,Q[0].clear();
siz[1]=0,Q[1].clear();
for(int i=1;i<=n*2;i++)vis[i]=fa[i]=dep[i]=0,v[i].clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11856kb
input:
4 3 1 2 2 3 2 4 4 5 4 6 3 1 2 1 3 1 4 1 5 1 6 4 1 2 2 3 3 4 4 5 5 6 6 7 7 8 5 1 2 1 4 4 3 4 5 5 6 5 8 8 7 8 9 9 10
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
result:
wrong answer participant reports no solution, but jury has one (test case 1)