QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#880805 | #9983. Color-Balanced Tree | dfgz | WA | 1ms | 6468kb | C++14 | 942b | 2025-02-03 20:52:30 | 2025-02-03 20:52:30 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
const int N = 1e5+10;
using namespace std;
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;
}
vector<int>e[N],k;
int n,tot,co[N];
void dfs(int x,int f,int c) {
if(e[x].size()==1) return ;
co[x]=c;
tot+=c;
for(auto v:e[x]) {
if(v==f) continue;
dfs(v,x,c*-1);
}
}
signed main() {
cin>>n;
n*=2;
for(int i=1,a,b;i<n;i++) {
cin>>a>>b;
e[a].push_back(b);
e[b].push_back(a);
}
int opt=1;
for(int i=1;i<=n;i++) {
if(e[i].size()==1) {
k.push_back(i);
}
else opt=i;
}
dfs(opt,opt,1);
for(auto v:k) {
if(tot>=0) {
tot--;
co[v]=-1;
}
else {
tot++;
co[v]=1;
}
}
for(int i=1;i<=n;++i) cout<<co[i]<<" ";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6468kb
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:
0 0 0 0 -1 -1 0 1
result:
wrong answer participant reports no solution, but jury has one (test case 1)