QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#876720 | #9983. Color-Balanced Tree | ucup-team6274 | WA | 20ms | 5680kb | C++20 | 2.4kb | 2025-01-31 11:45:48 | 2025-01-31 11:45:50 |
Judging History
answer
#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define siz(vec) ((int)(vec).size())
#define all(vec) (vec).begin(),(vec).end()
template<class T>
void operator +=(vec<T> &a,T b){a.push_back(b);}
template<class T>
void operator --(vec<T> &a){a.pop_back();}
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(exp) if(exp)continue;
#define stop(exp) if(exp)break;
#define ret(exp) if(exp)return;
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define debl(var) cerr<<#var<<'='<<(var)<<";\n"
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define int long long
#define inf (long long)(1e18)
template<class T>
bool Min(T &x,T y){return x>y?x=y,1:0;}
template<class T>
bool Max(T &x,T y){return x<y?x=y,1:0;}
const int mod=998244353;
void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,int y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans;
}
int n;
vec<int> g[100010];
int vis[100010],dep[100010],q[100010],r;
void work(){
cin>>n;
n<<=1;
for(int i=1;i<=n;i++){
g[i].clear();
vis[i]=0;
}
for(int i=1,u,v;i<n;i++){
cin>>u>>v;
g[u]+=v;
g[v]+=u;
}
q[r=1]=1;
dep[1]=0;
int l=1;
while(l<=r){
int u=q[l++];
vis[u]=1;
for(auto v:g[u]){
exc(vis[v]);
dep[v]=dep[u]^1;
q[++r]=v;
}
}
int x=count(dep+1,dep+n+1,1);
if(x<n/2){
for(int i=n;i&&x<n/2;i--){
int u=q[i];
if(!dep[u]){
dep[u]=1;
++x;
}
}
}else if(x>n/2){
for(int i=n;i&&x>n/2;i--){
int u=q[i];
if(dep[u]){
dep[u]=0;
--x;
}
}
}
for(int i=1;i<=n;i++){
cout<<dep[i]<<" \n"[i==n];
}
}
bool Med;
signed main(){
ios::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int T=1;cin>>T;while(T--)work();
// cerr<<"Time: "<<clock()<<" ms;\n";
// cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5680kb
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 1 0 0 1 1 0 1 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
result:
ok correct! (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 20ms
memory: 3712kb
input:
10000 10 3 1 14 11 17 14 18 12 2 5 9 1 5 19 9 18 13 4 4 6 15 6 2 8 8 20 3 11 7 13 12 10 7 10 20 16 19 17 4 8 4 1 5 5 3 8 2 6 4 2 7 5 4 1 2 1 2 3 2 2 4 4 1 5 4 5 8 1 3 9 10 2 7 2 8 6 6 9 4 7 3 10 3 1 4 6 5 4 3 5 3 2 6 6 12 10 7 6 11 7 5 11 8 11 2 7 4 1 3 10 4 2 9 4 2 10 12 19 6 8 15 16 18 1 18 18 12 ...
output:
0 1 1 1 0 0 1 0 1 0 0 1 0 1 1 0 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 1 1 1 0 ...
result:
wrong answer diff > 3 (test case 15)