# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
369149 | BartolM | Beads and wires (APIO14_beads) | C++17 | 1090 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const ll MAX=(ll)INF*INF;
const int N=205;
int n;
vector <pii> ls[N];
int dp[N][2];
int rek(int node, int fl, int par) {
int ret=dp[node][fl];
if (ret!=-1) return ret;
int sum0=0, ed;
for (pii sus:ls[node]) {
if (sus.X==par) {
ed=sus.Y;
continue;
}
sum0+=rek(sus.X, 0, node);
}
ret=sum0;
for (pii sus:ls[node]) {
if (sus.X==par) continue;
if (!fl) ret=max(ret, ed+sus.Y+sum0-rek(sus.X, 0, node)+rek(sus.X, 1, node));
}
return ret;
}
void load() {
scanf("%d", &n);
for (int i=0; i<n-1; ++i) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
ls[a].pb(mp(b, c));
ls[b].pb(mp(a, c));
}
}
int main() {
load();
int sol=0;
for (int i=1; i<=n; ++i) {
memset(dp, -1, sizeof dp);
sol=max(sol, rek(i, 1, 0));
}
printf("%d\n", sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |