QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#746870#4584. Not Oneshinonome_ena#WA 199ms19956kbC++231.1kb2024-11-14 15:46:252024-11-14 15:46:26

Judging History

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

  • [2024-11-14 15:46:26]
  • 评测
  • 测评结果:WA
  • 用时:199ms
  • 内存:19956kb
  • [2024-11-14 15:46:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define MAX 1010101
vector<int> lst[MAX];
int A[MAX];
int p[MAX];
int num[MAX];
vector<int> adj[MAX];
int chk[MAX];
int mx=1;
int find(int x) {
	if(p[x] == x) return x;
	return p[x] = find(p[x]);
}
void uni(int a, int b) {
	a = find(a);
	b = find(b);
	if(a == b) return;
	p[a] = b;
	num[b]+=num[a];
	mx = max(mx, num[b]);
}
void calc(vector<int> &arr){
	for(auto v:arr) {
		for(auto u:adj[v]) {
			if(chk[u]) uni(u, v);
		}
		chk[v] = 1;
	}
	for(auto v:arr) chk[v]=0;
}
signed main(){
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin>>N;
	int i, j;
	int amx=0;
	for(i=1;i<=N;i++) {
		cin>>A[i];
		amx = max(amx, A[i]);
		for(j=2;j*j<=A[i];j++) {
			if(A[i]%j) continue;
			lst[j].push_back(i);
			while(A[i]%j==0) A[i]/=j;
		}
	}
	int a, b;
	for(i=1;i<N;i++) {
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	if(amx == 1){
		cout<<0;
		return 0;
	}
	for(i=2;i<MAX;i++) {
		if(lst[i].size()) {
			for(j=1;j<=N;j++) p[j] = j, num[j] = 1;
			calc(lst[i]);
		}
	}
	cout<<mx;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 9800kb

input:

7
10 5 8 6 10 6 4
1 2
2 3
2 4
4 5
4 6
4 7

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 2ms
memory: 5700kb

input:

4
1 1 1 1
1 2
2 3
3 4

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 9796kb

input:

5
100 100 100 100 100
3 4
1 2
3 5
2 4

output:

5

result:

ok single line: '5'

Test #4:

score: 0
Accepted
time: 2ms
memory: 5632kb

input:

2
1 1
1 2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 129ms
memory: 19956kb

input:

100000
860163 795323 862289 543383 792647 337047 353985 959953 874318 573652 69827 958063 571741 704399 311826 920477 792478 151531 872269 592307 853819 865817 940735 620657 937154 696551 749279 552523 836161 707467 389626 459089 563763 668884 810391 639709 419361 580342 519595 836124 494959 669379 ...

output:

213

result:

ok single line: '213'

Test #6:

score: -100
Wrong Answer
time: 199ms
memory: 13384kb

input:

100000
999983 999983 999961 999961 999979 999979 999979 999961 999983 999961 999979 999961 999961 999983 999961 999983 999983 999979 999961 999979 999983 999979 999983 999961 999979 999961 999979 999979 999961 999979 999983 999979 999961 999961 999961 999961 999961 999983 999979 999983 999979 999961...

output:

1

result:

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