QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388578#7370. 懒惰的出题人Ecec24310 1ms8032kbC++231.3kb2024-04-13 17:07:062024-04-13 17:07:07

Judging History

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

  • [2024-04-13 17:07:07]
  • 评测
  • 测评结果:10
  • 用时:1ms
  • 内存:8032kb
  • [2024-04-13 17:07:06]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long a[500010],head[500010],tot=0,ans=1,n;
bool d1[500010],d2[500010];
long long p=1000000007;
struct jgt
{
	int x,y,nxt;
}e[500010];
long long lcm(long long s1,long long s2)
{
	long long t1=s1,t2=s2,r;
	for(r=t1%t2;r;t1=t2,t2=r,r=t1%t2);
	return s1/t2*s2%p;
}
void dfs(long long q,long long dep)
{
	long long i,js;
//	cout<<q<<' '<<dep<<" dfs\n";
	if(dep>=q)
	{
		for(js=1,i=1;i<=n;i++)
			if(d1[i]&&d2[i])
				js=lcm(js,a[i]);
//		cout<<js<<endl;
		ans=ans*js%p;
	}
	for(i=head[dep];i;i=e[i].nxt)
		if(!d2[e[i].y])
		{
			d2[e[i].y]=1;
			dfs(q,e[i].y);
			d2[e[i].y]=0;
		}
	return;
}
void DFS(long long q,long long dep)
{
	long long i;
//	cout<<q<<' '<<dep<<" DFS\n";
	if(dep>=q)
	{
		for(i=1;i<=n;i++)
			d2[i]=1,dfs(i,i),d2[i]=0;
	}
	for(i=head[dep];i;i=e[i].nxt)
		if(!d1[e[i].y])
		{
			d1[e[i].y]=1;
			DFS(q,e[i].y);
			d1[e[i].y]=0;
		}
	return;
}
int main()
{
	long long i,x,y;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(i=1;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		e[++tot].x=x,e[tot].y=y,e[tot].nxt=head[x],head[x]=tot;
		e[++tot].x=y,e[tot].y=x,e[tot].nxt=head[y],head[y]=tot;
	}
	for(i=1;i<=n;i++)
		d1[i]=1,DFS(i,i),d1[i]=0;
	printf("%lld",ans);
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 1ms
memory: 8032kb

input:

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

output:

570000028

result:

ok single line: '570000028'

Test #2:

score: 0
Time Limit Exceeded

input:

100
6 5 5 4 5 5 10 10 5 11 3 9 8 10 9 9 10 9 7 10 4 6 6 8 3 9 3 8 10 4 4 3 5 9 7 3 7 6 5 11 11 11 5 3 11 9 6 6 7 8 8 6 6 4 9 10 2 10 8 9 9 11 8 5 5 10 6 8 7 8 11 10 8 7 5 11 7 5 8 5 3 11 7 5 4 8 4 11 11 6 2 2 6 3 5 2 2 2 3 4
1 2
1 3
3 4
3 5
5 6
1 7
4 8
3 9
5 10
4 11
8 12
11 13
3 14
11 15
10 16
12 17...

output:


result:


Test #3:

score: 0
Time Limit Exceeded

input:

2000
9 7 6 2 4 8 8 10 10 10 2 4 4 6 2 9 4 7 5 7 5 3 4 10 11 6 8 7 11 6 6 4 4 3 5 10 8 3 7 4 6 7 5 10 7 3 3 8 10 10 2 8 6 8 2 3 9 9 4 4 6 10 9 11 1 10 1 5 11 11 3 1 10 7 3 9 2 3 7 4 5 2 9 9 4 2 10 6 2 7 7 10 2 5 10 2 5 10 8 5 11 7 11 7 1 2 6 6 2 11 4 7 2 1 11 7 11 3 2 4 3 3 9 5 6 1 7 1 6 8 8 3 10 6 9...

output:


result:


Test #4:

score: 0
Time Limit Exceeded

input:

20000
4184 6538 2361 8794 2149 4488 4698 7836 9122 6131 8230 1169 6975 9337 1142 3313 4570 9896 5440 3931 6054 6893 8680 601 8270 8124 4505 6230 3764 6413 2670 6640 9 4755 5531 3357 4890 6200 5389 9404 9926 7713 5408 5470 927 7425 2109 1702 7592 1407 3939 9326 2029 6600 5213 7084 966 940 1158 4034 9...

output:


result:


Test #5:

score: 0
Time Limit Exceeded

input:

20000
3277 3959 241 5424 9764 3941 6018 3056 7730 5835 3150 4243 1288 7449 842 6122 811 2725 6710 1017 1423 7102 2443 424 8317 3815 7621 7722 8429 3600 3607 2476 6570 9953 9915 8401 9820 988 6514 4600 5986 4763 2552 1868 5197 1937 595 4516 8693 1678 8884 3871 1272 3853 8691 5328 4630 607 1459 4334 3...

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

80000
4675 2856 1529 9648 9806 5817 7399 6801 2583 7459 6535 4161 4798 5172 4672 9138 2477 5503 7577 86 7811 6788 3006 4685 2961 8069 1140 6572 2902 9739 8695 5716 1731 3564 6981 8988 476 5033 7981 5838 8445 7863 974 3539 953 590 358 2957 1039 8147 2939 7155 5681 2189 8858 5267 2484 1486 8023 2830 6...

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

150000
126766 163939 161711 74916 19725 96106 28715 419852 46358 183125 111178 8839 374691 172561 485632 371931 415732 411816 486828 340254 435854 57597 292410 149136 209730 180213 445769 412768 280207 32922 450118 121498 294042 78565 292774 37836 151096 239592 384479 308853 355559 322805 421164 105...

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

200000
37733 63661 196570 15567 289864 150200 92731 355061 240633 374630 283879 22006 390789 17397 21254 141905 245417 471838 54991 71400 96265 336506 441107 356237 447601 322579 412804 399957 45065 144484 122549 293045 377404 31597 114307 401804 279583 440711 93815 385476 100534 173972 249133 18750...

output:


result:


Test #9:

score: 0
Runtime Error

input:

500000
411560 358266 291585 459238 108902 380546 131625 465575 292230 387329 187232 353499 456260 124508 458598 270117 81472 91403 322109 89582 22447 309914 480796 17393 259541 154452 141348 103228 121393 219441 307936 436983 376083 230912 485826 50480 339023 228408 183600 334415 50456 382609 404302...

output:


result:


Test #10:

score: 0
Runtime Error

input:

500000
282202 195076 271089 252585 373871 5268 446185 136265 397315 103636 341033 116774 462191 37008 341223 277022 300397 350193 405383 426837 111389 300106 94787 415147 121162 452311 212291 474660 46376 460097 143216 68255 180624 2607 228638 313040 424525 358497 67099 18011 418390 189328 255798 11...

output:


result: