QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#24095#2946. Abridged Readingmaze#WA 3ms3852kbC++141.1kb2022-03-26 13:50:142022-04-30 04:55:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 04:55:56]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3852kb
  • [2022-03-26 13:50:14]
  • 提交

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[temp.size() - 1] + temp[temp.size() - 2] - 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: 3844kb

input:

2 0
10 20

output:

30

result:

ok single line: '30'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

3 2
10 20 30
1 2
1 3

output:

60

result:

ok single line: '60'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3788kb

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'