이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, a[100009], b[100009], c[100009], maxn;
void dfs(vector<int>v, vector<int>w, int score) {
maxn = max(maxn, score);
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (v[i] == 1 || v[j] == 1) continue;
int a1 = -1, a2 = -1, p = -1;
if (a[i] == a[j]) { a1 = b[i]; a2 = b[j]; p = a[i]; }
if (a[i] == b[j]) { a1 = b[i]; a2 = a[j]; p = a[i]; }
if (b[i] == a[j]) { a1 = a[i]; a2 = b[j]; p = b[i]; }
if (b[i] == b[j]) { a1 = a[i]; a2 = a[j]; p = b[i]; }
if (a1 == -1 || w[p] == 1) continue;
vector<int>v1 = v, w1 = w;
v1[i] = 1; v1[j] = 1;
w1[p] = 1;
dfs(v1, w1, score + c[i] + c[j]);
}
}
}
int main() {
// --------------- 13 points solution ---------------
cin >> n;
for (int i = 0; i < n - 1; i++) {
cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--;
}
vector<int>S(n - 1, 0), T(n, 0);
dfs(S, T, 0);
cout << maxn << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
beads.cpp: In function 'void dfs(std::vector<int>, std::vector<int>, int)':
beads.cpp:14:17: warning: variable 'a2' set but not used [-Wunused-but-set-variable]
int a1 = -1, a2 = -1, p = -1;
^~
# | 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... |