QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#699918#7733. Cool, It’s Yesterday Four Times Moreone_zero_two_zeroWA 3ms30488kbC++141.3kb2024-11-02 11:15:212024-11-02 11:15:22

Judging History

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

  • [2024-11-02 11:15:22]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:30488kb
  • [2024-11-02 11:15:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

struct node{
    long long sum, now;
    bool operator < (const node &a) const{
        return sum < a.sum;
    }
};

int N;
int u, v;
long long val[1000006];
long long dp[1000006];
vector<int> E[1000006];
int fa[1000006];

void erg(int u){
    for (auto && v : E[u]){
        if (v == fa[u]) continue;
        fa[v] = u;
        erg(v);
    }
}

void dfs(int u){
    vector<node> tmp;
    for (auto && v : E[u]){
        if (v == fa[u]) continue;
        dfs(v);
        tmp.push_back({val[v] + dp[v], val[v]});
    }
    if (tmp.empty()){
        dp[u] = 0;
        return;
    }
    sort(tmp.begin(), tmp.end());
    dp[u] = tmp[tmp.size() - 1].sum - tmp[tmp.size() - 1].now;
    printf("%d %d;;\n", u, dp[u]);
    if (tmp.size() >= 2){
        dp[u] = max(dp[u], tmp[tmp.size() - 2].sum);
    }
    printf("%d %d\n", u, dp[u]);
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("../data.in", "r", stdin);
    freopen("../data.out", "w", stdout);
#endif

    scanf("%d", &N);
    for (int i = 2; i <= N; i ++){
        scanf("%lld", &val[i]);
    }
    for (int i = 1; i < N; i ++){
        scanf("%d %d", &u, &v);
        E[u].push_back(v);
        E[v].push_back(u);
    }
    erg(1);
    dfs(1);
    printf("%lld\n", dp[1]);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 30488kb

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:

0

result:

wrong answer 1st lines differ - expected: '3', found: '0'