QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118032#6629. Travelling Traderpandapythoner#0 1ms3728kbC++201.2kb2023-07-02 22:31:282024-05-31 18:47:46

Judging History

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

  • [2024-05-31 18:47:46]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3728kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-02 22:31:28]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(234);
const ll inf = 1e18;

int n, k;
vector<ll> a;
vector<vector<int>> g;

void dfs0(int v, int p) {
    auto it = find(all(g[v]), p);
    if (it != g[v].end()) {
        g[v].erase(it);
    }
    for (auto to : g[v]) {
        dfs0(to, v);
    }
}

void dfs1(int v, ll sm, ll &rs) {
    sm += a[v];
    rs = max(rs, sm);
    for (auto to : g[v]) {
        dfs1(to, sm, rs);
    }
}

ll solve() {
    ll rs = 0;
    if (k == 1) {
        dfs1(0, 0, rs);
        return rs;
    }
    return -1;
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    cin >> n >> k;
    g.assign(n, vector<int>());
    for (int i = 0; i < n - 1; i += 1) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    a.resize(n);
    for (int i = 0; i < n; i += 1) {
        cin >> a[i];
    }
    dfs0(0, -1);
    cout << solve() << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3532kb

input:

2 1
1 2
255959470 961356354

output:

1217315824

result:

wrong output format Unexpected end of file - int32 expected

Subtask #2:

score: 0
Wrong Answer

Test #12:

score: 0
Wrong Answer
time: 0ms
memory: 3524kb

input:

2 2
2 1
243296356 635616793

output:

-1

result:

wrong output format Unexpected end of file - int32 expected

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #83:

score: 0
Wrong Answer
time: 1ms
memory: 3728kb

input:

2000 3
1359 90
1703 163
158 188
360 1501
195 664
1414 215
1546 1756
536 1096
1726 1223
1150 104
1757 703
1982 282
1023 998
1180 419
576 1759
1496 1993
44 670
1703 952
855 849
1998 1399
1280 980
1533 1090
1270 678
1680 387
469 1734
1799 263
473 588
303 226
5 295
1489 1471
1094 1667
1912 210
1368 1360...

output:

-1

result:

wrong output format Unexpected end of file - int32 expected

Subtask #6:

score: 0
Skipped

Dependency #5:

0%