1 条题解

  • 0
    @ 2026-9-19 17:27:35

    设 x=max⁡{ai}x=\max\{a_i\}。

    若所有 ai∣xa_i \mid x,则可以构造(设 ap=xa_p=x,则以 pp 为根,将其它结点接在 pp 下面)

    否则显然不能构造。

    时间复杂度 O(n)O(n),可以通过。

    #include<bits/stdc++.h>
    using namespace std;
    const int N=100100;
    int T,n,mx,f,a[N];
    int main(){
    	cin>>n;
    	for(int i=1;i<=n;i++) cin>>a[i],mx=max(mx,a[i]);
    	for(int i=1;i<=n;i++) f|=(mx%a[i]!=0);
    	cout<<(f?"No\n":"Yes\n");
    	return 0;
    }
    

    信息

    ID
    304
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    5
    已通过
    4
    上传者