이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
// trans rights
#define ll long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
#define MOD 1000000009
vector<int> grph[1069];
int con[1069];
bool done[1069];
int dp[1069][2];
int ans = 0;
int dfs1(int x) {
if (done[x]) return 0;
done[x] = true;
int rtn = con[x];
for (auto i : grph[x]) rtn = max(rtn, dfs1(i));
return rtn;
}
int dfs2(int x, int lst, int chs = 1) {
if (dp[x][chs]) return dp[x][chs]; //only 0 at the edges anyway
if (!chs) {
for (auto i : grph[x]) if (i != lst) dp[x][chs] += dfs2(i, x, 1);
return dp[x][chs];
}
dp[x][chs] += con[x];
for (auto i : grph[x]) if (i != lst) dp[x][chs] += dfs2(i, x, 0);
return dp[x][chs] = max(dp[x][chs], dp[x][0]);
}
int findSample(int n, int confidence[], int host[], int protocol[]){
if (n <= 10) {
for (int i = 1; i < n; i++) {
if (protocol[i] != 1) {
grph[i].push_back(host[i]);
}
if (protocol[i] != 0) {
for (auto t : grph[host[i]]) {
grph[i].push_back(t);
}
}
}
for (int bst = 0; bst < (1 << 10); bst++) {
int cur = 0;
bool flag = true;
for (int i = 0; i < n; i++) {
if (!(bst & (1 << i))) continue;
for (auto j : grph[i]) if (bst & (1 << j)) {
flag = false;
}
cur += confidence[i];
}
if (flag) ans = max(ans, cur);
}
return ans;
}
bool flag = true;
for (int i = 1; i < n; i++) if (protocol[i] != 1) flag = false;
if (flag) return 0; //so troll
for (int i = 0; i < n; i++) con[i] = confidence[i];
flag = true;
for (int i = 1; i < n; i++) if (protocol[i] != 2) flag = false;
if (flag) {
for (int i = 1; i < n; i++) grph[i].push_back(host[i]);
for (int i = 0; i < n; i++) {
ans += dfs1(i);
}
return ans;
}
flag = true;
for (int i = 1; i < n; i++) if (protocol[i] != 0) flag = false;
if (flag) {
for (int i = 1; i < n; i++) grph[i].push_back(host[i]);
for (int i = 0; i < n; i++) {
ans += dfs2(i, -1);
}
return ans;
}
return ans;
}
# | 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... |