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 int long long
int inf = 2e9;
int n;
vector<pair<int,pair<int,int>>> e;
bool iau[25];
int ans;
int fr[15];
void afis()
{
for (int i = 1; i <= n; i++)
fr[i] = 0;
int cst = 0;
for (int i = 0; i < n - 1; i++)
{
if (!iau[i])
continue;
if (iau[n - 1 + i])
fr[e[i].second.first]++;
else
fr[e[i].second.second]++;
cst += e[i].first;
}
for (int i = 1; i <= n; i++)
if (fr[i] != 0 and fr[i] != 2)
return;
ans = max(ans,cst);
}
void bkt(int pos)
{
if (pos == 2 * n - 2)
afis();
else
{
iau[pos] = false;
bkt(pos + 1);
iau[pos] = true;
bkt(pos + 1);
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i < n; i++)
{
int x,y,z;
cin >> x >> y >> z;
e.push_back({z,{x,y}});
}
if (n <= 2)
{
cout << 0;
return 0;
}
bkt(0);
cout << ans;
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... |