QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607022#72. MergersSimonLJK0 2ms9828kbC++14936b2024-10-03 13:39:312024-10-03 13:39:32

Judging History

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

  • [2024-10-03 13:39:32]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:9828kb
  • [2024-10-03 13:39:31]
  • 提交

answer

// LUOGU_RID: 179653037
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=1e6+999;
int n,c[N];
ull val[N],cval[N];
mt19937_64 ran(1567184113);
struct edge{
	int v,nxt;
}edg[N*2];
int cntedge,hd[N];
void add(int u,int v){
	edg[++cntedge]=(edge){v,hd[u]};
	hd[u]=cntedge;
}
int ans,b[N];
void dfs(int u,int fa){
	int v;
	for(int i=hd[u];i;i=edg[i].nxt){
		v=edg[i].v;
		if(v==fa) continue;
		dfs(v,u);
		val[u]^=val[v];
		b[u]+=b[v];
	}
	if(!b[u]&&!val[u]&&u!=1){
		ans++;
		b[u]=1; 
	}
	return;
}
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int u,v;
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		add(u,v);
		add(v,u);
	}
	for(int i=1;i<=n;i++){
		cin>>c[i];
		val[i]=ran();
		cval[c[i]]^=val[i];
	}
	for(int i=1;i<=n;i++){
		val[i]^=cval[c[i]];
		cval[c[i]]=0;
	}
	dfs(1,0);
	if(b[1]==1) ans++;
	cout<<(ans+1)/2;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 2ms
memory: 9828kb

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Wrong Answer
time: 2ms
memory: 9816kb

input:

3 2
2 1
3 1
2
2
1

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Memory Limit Exceeded

Test #66:

score: 0
Memory Limit Exceeded

input:

100000 100000
14957 4585
67467 70858
61843 47396
50630 17382
61027 39858
94990 21698
10240 22940
23505 67581
91432 14182
22040 40125
24556 60351
75822 41519
82801 23601
90653 29138
85096 34582
99587 59109
8932 45189
18235 36632
43160 14939
67600 76675
60175 65542
99294 53955
46429 66931
16822 48854
...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%