QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69204#4584. Not Onehjroh0315WA 29ms4516kbC++20807b2022-12-25 13:15:062022-12-25 13:15:07

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int dsu[101010],sz[101010];
    auto reset=[&](int v)->void{dsu[v]=v;sz[v]=1;};
    function<int(int)>find=[&](int v)->int{if(v==dsu[v])return v;return dsu[v]=find(dsu[v]);};
    auto merge=[&](int a,int b){a=find(a);b=find(b);if(a!=b){if(sz[a]<sz[b])swap(a,b);dsu[b]=a;sz[a]+=sz[b];}};
    int n;cin>>n;
    for(int i=0;i<=n;i++)reset(i);
    int a[n];for(int&i:a)cin>>i;
    for(int i=0;i<n-1;i++)
    {
        int o,p;cin>>o>>p;
        if(gcd(a[o-1],a[p-1])>1)
        {
            merge(o,p);
            a[o-1]=a[p-1]=gcd(a[o-1],a[p-1]);
        }
    }
    int msz=0;
    for(int i=1;i<=n;i++)
    {
        if(sz[i]>1||a[i-1]>1)msz=max(sz[i],msz);
    }
    cout<<msz;
}

详细

Test #1:

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

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: 3320kb

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: 2ms
memory: 3324kb

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: 3320kb

input:

2
1 1
1 2

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 29ms
memory: 4516kb

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:

117

result:

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