QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#256379 | #6437. Paimon's Tree | Satsuki# | WA | 5ms | 5876kb | C++14 | 1.3kb | 2023-11-18 18:59:30 | 2023-11-18 18:59:31 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i <= r; ++ i)
#define int long long
using namespace std;
const int MAXN = 1e5 + 10;
int read()
{
char cc(getchar()); int cn(0), flus(1);
while(!isdigit(cc)) {if(cc == '-') flus = -flus; cc = getchar();}
while(isdigit(cc)) cn = cn * 10 + cc - 48, cc = getchar();
return cn * flus;
}
struct edge
{
int to, next;
} e[MAXN << 1];
int n, tot;
int mdep, mp;
int head[MAXN], a[MAXN];
void add(int u, int v)
{
e[++tot].next = head[u];
head[u] = tot;
e[tot].to = v;
}
void init()
{
tot = 0;
rep(i, 1, n + 1) head[i] = 0;
}
void dfs(int u, int fa, int dep)
{
if(dep > mdep)
{
mdep = dep;
mp = u;
}
for(int i = head[u]; i; i = e[i].next)
{
int v = e[i].to;
if(v == fa) continue;
dfs(v, u, dep + 1);
}
}
signed main()
{
int T = read();
while(T --)
{
n = read();
init();
rep(i, 1, n) a[i] = read();
rep(i, 1, n)
{
int u = read(), v = read();
add(u, v);
add(v, u);
}
mdep = mp = 0;
dfs(1, 0, 0);
int st = mp;
mdep = mp = 0;
dfs(st, 0, 0);
sort(a + 1, a + 1 + n);
int ans(0);
for(int i = n; i >= n - mdep + 1; -- i)
{
ans += a[i];
}
printf("%lld\n", ans);
}
return 0;
}
/*
2
5
1 7 3 5 4
1 3
2 3
3 4
4 5
4 6
1
1000000000
1 2
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5876kb
input:
2 5 1 7 3 5 4 1 3 2 3 3 4 4 5 4 6 1 1000000000 1 2
output:
16 1000000000
result:
ok 2 number(s): "16 1000000000"
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3824kb
input:
5000 19 481199252 336470888 634074578 642802746 740396295 773386884 579721198 396628655 503722503 971207868 202647942 2087506 268792718 46761498 443917727 16843338 125908043 691952768 717268783 9 4 4 18 12 9 10 9 4 1 6 12 2 18 9 13 6 14 4 8 2 3 10 17 2 20 19 20 5 1 12 15 15 16 4 7 17 11 4 240982681 ...
output:
5750811120 1896999359 4208559611 4140156713 5361004844 1875024569 3690026656 3702623113 3412485417 7807375141 5341435147 2355946110 3090496776 5626636202 4729664767 2207592767 572868833 4759005973 2944749369 2538044586 3083947956 5757497518 1421427135 3971435093 1197051728 396588615 251138097 221986...
result:
wrong answer 48th numbers differ - expected: '5317528311', found: '5514819848'