Submission #285603

#TimeUsernameProblemLanguageResultExecution timeMemory
2856032qbingxuan친구 (IOI14_friend)C++14
27 / 100
1 ms512 KiB
#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]);
    }
    if(isBipartite()) {
        safe;
        vector<bool> parity(n);
        long long w[2] = {};
        for(int i = 1; i < n; i++) parity[i] = !parity[host[i]];
        for(int i = 0; i < n; i++) w[parity[i]] += confidence[i];
        return max(w[0], w[1]);
    }
    return -1;
}

Compilation message (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;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...