QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55386#4229. GCD HarmonyKieray#WA 2ms3800kbC++1.0kb2022-10-13 15:07:102022-10-13 15:07:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-13 15:07:13]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3800kb
  • [2022-10-13 15:07:10]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<numeric>
#include<cmath>
using namespace std;
#define ll long long
#define ge getchar 
#define pun putchar('\n')
#define pu putchar
#define puk putchar(' ')
#define pb push_back
typedef vector<int> vint;
const int nn=5006,mm=nn*2;
int n,a[nn];
int z[nn],x[mm],t[mm],f[nn][101];
void ff(int u,int fu){
	for(int k=2;k<=100;k++)f[u][k]=(u==k)?0:k;
	for(int i=z[u];i;i=x[i]){
		int v=t[i];
		if(v!=fu){
			ff(v,u);
			for(int k=2;k<=100;k++){
				int zx=f[v][k];
				for(int h=2;h<=100;h++)if(__gcd(k,h)>1){
					zx=min(zx,f[v][h]);
				}
				f[u][k]+=zx;
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int ki=1;
	for(int i=2;i<=n;i++){
		int u,v;scanf("%d%d",&u,&v);
		x[++ki]=z[u],z[u]=ki,t[ki]=v;
		x[++ki]=z[v],z[v]=ki,t[ki]=u;
	}
	ff(1,0);
	int zx=f[1][2];
	for(int k=2;k<=100;k++)zx=min(zx,f[1][k]);
	cout<<zx<<endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3800kb

input:

6
5
6
3
4
9
12
1 2
1 3
1 4
1 6
3 5

output:

6

result:

ok single line: '6'

Test #2:

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

input:

3
1
2
3
3 1
2 3

output:

4

result:

ok single line: '4'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3764kb

input:

13
2
5
5
5
5
5
5
3
3
3
3
3
3
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13

output:

14

result:

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