제출 #1011891

#제출 시각아이디문제언어결과실행 시간메모리
1011891andrei_iorgulescu구슬과 끈 (APIO14_beads)C++14
0 / 100
6 ms460 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...