QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#865061#9983. Color-Balanced TreeyhdddWA 0ms7888kbC++201.4kb2025-01-21 14:26:442025-01-21 14:26:45

Judging History

你现在查看的是最新测评结果

  • [2025-01-21 14:26:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7888kb
  • [2025-01-21 14:26:44]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n;
int head[maxn],tot;
struct nd{
	int nxt,to;
}e[maxn<<1];
void add(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
int col[maxn];
void dfs(int u,int fa){
	col[u]=col[fa]^1;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;if(v==fa)continue;
		dfs(v,u);
	}
}
void work(){
	n=read();
	for(int i=1;i<=2*n;i++)head[i]=0;tot=0;
	for(int i=1;i<2*n;i++){
		int u=read(),v=read();
		add(u,v),add(v,u);
	}
	dfs(1,0);
	int num=0;for(int i=1;i<=2*n;i++)num+=col[i]*2-1;
	if(num<0){
		for(int i=1;i<=2*n;i++)col[i]=1-col[i];num=-num;
	}
	for(int i=2;i<=2*n;i++)if(!e[head[i]].nxt&&col[i]&&num){
		col[i]=0;
		num/=2;
	}
	for(int i=1;i<=2*n;i++)printf("%lld ",col[i]);puts("");
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=read();
	while(T--)work();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7888kb

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 0 1 1 0 0 
0 0 0 0 1 1 
1 0 1 0 1 0 1 0 
1 0 1 0 1 0 1 0 1 0 

result:

wrong answer The number of black vertices and red vertices are not equal (test case 2)