QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93545#4229. GCD HarmonylinakRE 0ms0kbC++171.2kb2023-04-01 12:20:232023-04-01 12:20:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-01 12:20:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-04-01 12:20:23]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

vector<vector<int>> dp(5001,vector<int>(2001));
vector<int> adj[5001],k(5001),kdj[5001];
bool vi[5001];

vector<int> rec(int x){
    vi[x]=true;
    for(int i=2; i<=5000; i++){
        if(k[x]%i==0) dp[x][i]=0;
        else dp[x][i]=i;
    }
    for(int u: adj[x]){
        if(!vi[u]){
            vector<int> t=rec(u);
            for(int i=2; i<=5000; i++){
                int r=1e9;
                for(int v:kdj[i]) r=min(r,t[v]);
                dp[x][i]+=r;
            }
        }
    }
    for(int i=2; i<=5000; i++){
        for(int j=2*i; j<=5000; j+=i) dp[x][i]=min(dp[x][j],dp[x][i]);
    }
    return dp[x];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    for(int i=2; i<=5000; i++){
        for(int j=i; j<=5000; j+=i) kdj[j].push_back(i);
    }

    int a;
    cin>>a;
    for(int i=1; i<=a; i++) cin>>k[i];
    for(int i=1; i<a; i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    rec(1);
    int ans=1e9;
    for(int i=2; i<=5000; i++) ans=min(ans,dp[1][i]);
    cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

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

output:


result: