Submission #122466

# Submission time Handle Problem Language Result Execution time Memory
122466 2019-06-28T11:11:39 Z youngyojun Beads and wires (APIO14_beads) C++11
28 / 100
1000 ms 5376 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define upmax(a,b) (a)=max((a),(b))
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXN = 200055;

ll D[MAXN], E[MAXN];

vector<int> G[MAXN];
int A[MAXN], B[MAXN], C[MAXN];

ll Ans;
int N;

void f(int i, int p, int pe) {
	D[i] = 0; E[i] = -INFLL;
	for(int e : G[i]) {
		int v = A[e]^B[e]^i;
		if(v == p) continue;
		f(v, i, C[e]);
		upmax(E[i], -max(D[v], E[v]) + D[v] + C[e]);
		D[i] += max(D[v], E[v]);
	}
	E[i] += D[i] + pe;
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i < N; i++) {
		cin >> A[i] >> B[i] >> C[i];
		G[A[i]].eb(i);
		G[B[i]].eb(i);
	}

	for(int i = 1; i <= N; i++) {
		ll ret = 0;
		for(int e : G[i]) {
			int v = A[e]^B[e]^i;
			f(v, i, C[e]);
			ret += max(D[v], E[v]);
		}
		upmax(Ans, ret);
	}

	cout << Ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 8 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Correct 5 ms 4992 KB Output is correct
7 Correct 6 ms 4992 KB Output is correct
8 Correct 5 ms 5120 KB Output is correct
9 Correct 5 ms 4992 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 8 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Correct 5 ms 4992 KB Output is correct
7 Correct 6 ms 4992 KB Output is correct
8 Correct 5 ms 5120 KB Output is correct
9 Correct 5 ms 4992 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5248 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 8 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Correct 5 ms 4992 KB Output is correct
7 Correct 6 ms 4992 KB Output is correct
8 Correct 5 ms 5120 KB Output is correct
9 Correct 5 ms 4992 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5248 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Execution timed out 1063 ms 5376 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 8 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Correct 5 ms 4992 KB Output is correct
7 Correct 6 ms 4992 KB Output is correct
8 Correct 5 ms 5120 KB Output is correct
9 Correct 5 ms 4992 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 6 ms 5120 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5248 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Execution timed out 1063 ms 5376 KB Time limit exceeded
24 Halted 0 ms 0 KB -