QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#24096 | #2946. Abridged Reading | maze# | WA | 3ms | 3928kb | C++14 | 1.0kb | 2022-03-26 13:51:41 | 2022-04-30 04:55:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 1010
#define pb push_back
int fa[N];
int v[N];
vector<int> e[N];
int len[N];
int mi[N];
int ans;
void dfs(int r, int l)
{
len[r] = l + v[r];
if (e[r].size() == 0)
{
mi[r] = len[r];
return;
}
vector<int> temp;
for (int i = 0; i < e[r].size(); i++)
{
dfs(e[r][i], l + v[r]);
mi[r] = min(mi[r], mi[e[r][i]]);
temp.pb(mi[e[r][i]]);
}
if (e[r].size() > 1)
{
sort(temp.begin(), temp.end());
ans = min(ans, temp[0] + temp[1] - len[r]);
}
}
int main()
{
int n, m;
scanf("%d%d", &n, &m);
mi[0] = N;
for (int i = 1; i <= n; i++)
{
scanf("%d", &v[i]);
mi[i] = N;
}
for (int i = 0; i < m; i++)
{
int a, b;
scanf("%d%d", &a, &b);
fa[b] = a;
}
for (int i = 1; i <= n; i++)
{
e[fa[i]].pb(i);
}
ans = N * N;
dfs(0, 0);
printf("%d\n", ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3900kb
input:
2 0 10 20
output:
30
result:
ok single line: '30'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3872kb
input:
3 2 10 20 30 1 2 1 3
output:
60
result:
ok single line: '60'
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 3928kb
input:
1000 999 589 300 181 203 350 691 812 963 333 957 894 681 630 24 774 397 768 215 403 868 995 248 156 160 528 940 862 965 889 535 939 782 453 935 641 733 864 681 364 225 661 198 305 778 17 901 408 208 134 555 316 57 128 821 307 882 519 302 5 421 194 348 491 912 820 156 797 254 374 70 175 95 497 315 17...
output:
-5452
result:
wrong answer 1st lines differ - expected: '1196', found: '-5452'