이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
void qqbx(const char *s) {}
template <typename H, typename ...T> void qqbx(const char *s, const H& h, T&& ...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v),end(v)
using namespace std;
int findSample(int n, int confidence[], int host[], int protocol[]){
int ans = 0;
auto isBipartite = [&]() -> bool {
for(int i = 1; i < n; i++) if(protocol[i] != 1) return false;
return true;
};
auto isComplete = [&]() -> bool {
for(int i = 1; i < n; i++) if(protocol[i] != 2) return false;
return true;
};
auto isTree = [&]() -> bool {
for(int i = 1; i < n; i++) if(protocol[i] != 0) return false;
return true;
};
if(isComplete()) {
return *max_element(confidence, confidence+n);
}
if(isTree()) {
vector<vector<int>> g(n);
vector<array<int,2>> dp(n);
for(int i = 1; i < n; i++) g[host[i]].pb(i);
function<void(int,int)> dfs = [&](int i, int p) {
dp[i][0] = 0, dp[i][1] = confidence[i];
for(int j: g[i]) {
if(j == p) continue;
dfs(j, i);
dp[i][0] += max(dp[j][0], dp[j][1]);
dp[i][1] += dp[j][0];
}
};
dfs(0, -1);
return max(dp[0][0], dp[0][1]);
}
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:21:9: warning: unused variable 'ans' [-Wunused-variable]
21 | int ans = 0;
| ^~~
friend.cpp:22:10: warning: variable 'isBipartite' set but not used [-Wunused-but-set-variable]
22 | auto isBipartite = [&]() -> bool {
| ^~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |