QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880806#9983. Color-Balanced TreexleeeWA 1ms9544kbC++14689b2025-02-03 20:52:352025-02-03 20:52:35

Judging History

This is the latest submission verdict.

  • [2025-02-03 20:52:35]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 9544kb
  • [2025-02-03 20:52:35]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
vector<int>e[N];
int a[N],n,tot,cnt;
int ans[N];
void dfs(int u,int fa,int col)
{
	if(e[u].size()==1)return ;
	tot+=col;
	ans[u]=col;
	for(auto i:e[u])
	{
		if(i==fa)continue;
		dfs(i,u,tot*-1);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<2*n;++i)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	int st=1;
	for(int i=1;i<=2*n;++i)
	{
		if(e[i].size()==1)a[++cnt]=i;
		else st=i;
	}
	dfs(st,st,1);
	for(int i=1;i<=cnt;++i)
	{
		if(tot>=0)ans[a[i]]=-1,tot--;
		else ans[a[i]]=1;tot++;
	}
	for(int i=1;i<=2*n;++i)cout<<ans[i]<<' ';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9544kb

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)