Submission #83187

#TimeUsernameProblemLanguageResultExecution timeMemory
83187RezwanArefin01Beads and wires (APIO14_beads)C++17
28 / 100
1064 ms10112 KiB
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit; #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 10; vector<int> adj[N], cost[N]; ll S[N], M[N]; int n, pcost[N]; void calc(int u, int par) { for(int i = 0; i < adj[u].size(); i++) { int v = adj[u][i], c = cost[u][i]; if(v == par) continue; pcost[v] = c; calc(v, u); S[u] += max(S[v], M[v]); } for(int v : adj[u]) if(v - par) { M[u] = max(M[u], S[u] - max(S[v], M[v]) + S[v] + pcost[u] + pcost[v]); } } int main() { int n; scanf("%d", &n); for(int i = 1; i < n; i++) { int u, v, c; scanf("%d %d %d", &u, &v, &c); adj[u].push_back(v); adj[v].push_back(u); cost[u].push_back(c); cost[v].push_back(c); } ll ans = 0; for(int i = 1; i <= n; i++) { pcost[i] = 0; for(int j = 1; j <= n; j++) S[j] = M[j] = 0; calc(i, 0); ans = max(ans, S[i]); } printf("%lld\n", ans); }

Compilation message (stderr)

beads.cpp: In function 'void calc(int, int)':
beads.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:25:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d", &n);
            ~~~~~^~~~~~~~~~
beads.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &u, &v, &c); 
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...