/ SeriousOJ /

Record Detail

Compile Error

foo.cs(2,0): error CS1024: Wrong preprocessor directive
foo.cs(2,6): error CS1525: Unexpected symbol `namespace', expecting `identifier' or `static'
foo.cs(2,19): error CS1525: Unexpected symbol `;', expecting `identifier' or `static'
foo.cs(4,27): error CS1514: Unexpected symbol `[', expecting `.' or `{'
foo.cs(4,32): error CS1525: Unexpected symbol `;'

Code

#include <iostream>
using namespace std;
const int MAXN = 200005;
vector<pair<int, int>> adj[MAXN];
vector<long long> weights(MAXN), depth(MAXN), totalWeight(MAXN);
void dfs(int node, int parent) {
    totalWeight[node] = weights[node];
    for (auto [next, cost] : adj[node]) {
        if (next == parent) continue;
        depth[next] = depth[node] + cost;
        dfs(next, node);
        totalWeight[node] += totalWeight[next];
    }
}
int main() {
    int T;
    cin >> T;

    while (T--) {
        int N;
        cin >> N;
        for (int i = 1; i <= N; ++i) {
            cin >> weights[i];
            adj[i].clear();
        }
        for (int i = 0; i < N - 1; ++i) {
            int u, v, c;
            cin >> u >> v >> c;
            adj[u].push_back({v, c});
            adj[v].push_back({u, c});
        }
        depth.assign(N + 1, 0);
        dfs(1, 0);
        long long maxCycleWeight = LLONG_MIN;
        for (int u = 1; u <= N; ++u) {
            for (int v = u + 1; v <= N; ++v) {
                // Use depth to calculate cost of path from u to v
                long long cost = depth[u] + depth[v];
                long long cycle = totalWeight[u] + totalWeight[v] - cost;
                maxCycleWeight = max(maxCycleWeight, cycle);
            }
        }
        cout << maxCycleWeight << '\n';
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1205 E. Make Cycle in Tree
Contest
Educational Round 1
Language
C# 7 (Mono 6.8)
Submit At
2025-07-14 16:15:41
Judged At
2025-07-14 16:15:41
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes