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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N, A[100009], B[100009], C[100009], e[10], f[10], g[10][10], maxn;
int main() {
cin >> N;
for (int i = 0; i < N - 1; i++) { cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--; }
int d[10] = { 0,1,2,3,4,5,6,7,8,9 };
do {
for (int i = 0; i < N; i++) { e[i] = 0; f[i] = 0; }
int cnt = 0; bool OK = true;
for (int i = 0; i < N - 1; i++) {
if (d[A[i]] < d[B[i]]) { g[B[i]][e[B[i]]] = A[i]; e[B[i]]++; f[B[i]] += C[i]; }
else { g[A[i]][e[A[i]]] = B[i]; e[A[i]]++; f[A[i]] += C[i]; }
}
for (int i = 0; i < N; i++) {
if (e[i] >= 3) OK = false;
if (e[i] == 2 && (e[g[i][0]] >= 1 && e[g[i][1]] >= 1)) OK = false;
if (e[i] == 2) cnt += f[i];
}
if (OK == true) maxn = max(maxn, cnt);
} while (next_permutation(d, d + N));
cout << maxn << endl;
return 0;
}
# | 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... |