Submission #106077

#TimeUsernameProblemLanguageResultExecution timeMemory
106077SaboonBeads and wires (APIO14_beads)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int maxn = 2e5 + 10;
const int inf = 1e8;
 
int dp[maxn], pd[maxn];
vector<pair<int, int> > t[maxn];
 
void dfs(int v, int par = -1){
	int mx = -inf;
	dp[v] = 0;
	for (auto edge : t[v]){
		if (edge.first != par){
			dfs(edge.first, v);
			dp[v] += max(dp[edge.first], pd[edge.first] + edge.second);
			mx = max(mx, dp[u] + c - max(dp[u], pd[u] + c)); 
		}
	}
	pd[v] = dp[v] + mx;
}
 
int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++){
		int v, u, c;
		scanf("%d%d%d", &v, &u, &c);
		t[v].push_back({u, c});
		t[u].push_back({v, c});
	}
	int answer = 0;
	for (int v = 1; v <= n; v++){	
		dfs(v);
		answer = max(answer, dp[v]);
	}
	printf("%d\n", answer);
}

Compilation message (stderr)

beads.cpp: In function 'void dfs(int, int)':
beads.cpp:20:20: error: 'u' was not declared in this scope
    mx = max(mx, dp[u] + c - max(dp[u], pd[u] + c)); 
                    ^
beads.cpp:20:25: error: 'c' was not declared in this scope
    mx = max(mx, dp[u] + c - max(dp[u], pd[u] + c)); 
                         ^
beads.cpp: In function 'int main()':
beads.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
beads.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &v, &u, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~