QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#425412 | #4229. GCD Harmony | sitablechair | WA | 1ms | 3716kb | C++14 | 1.1kb | 2024-05-30 10:35:07 | 2024-05-30 10:35:08 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,r,l) for(int i=r;i>=l;i--)
#define REP(i,l,r) For(i,l,r-1)
#define PER(i,r,l) ForD(i,r-1,l)
#define ff first
#define ss second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define sz(a) (signed)a.size()
#ifdef NCGM
#include"debug.h"
#else
#define debug(...) "fr";
#endif
using namespace std;
const int N=5002,MAX=10000;
vector<int> adj[N];
int a[N],b[N];
bool vs[N];
ll res=0;
void dfs(int u,int cur) {
if (vs[u]) return;
vs[u]=1;
if (b[u]%cur) b[u]=cur,res+=cur;
for(auto v: adj[u]) {
if (!vs[v]) dfs(v,cur);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
For(i,1,n) cin >> a[i];
For(i,1,n-1) {
int a,b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
ll ans=LLONG_MAX;
For(i,2,MAX) {
res=0;
For(j,1,n) b[j]=a[j];
For(j,1,n) vs[j]=0;
dfs(1,i);
ans=min(ans,res);
}
cout << ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
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: 1ms
memory: 3716kb
input:
3 1 2 3 3 1 2 3
output:
4
result:
ok single line: '4'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3712kb
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:
21
result:
wrong answer 1st lines differ - expected: '15', found: '21'