제출 #285635

#제출 시각아이디문제언어결과실행 시간메모리
285635ToMmyDong친구 (IOI14_friend)C++11
16 / 100
14 ms6784 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define first X
#define second Y
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define SZ(i) int(i.size())
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do (T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream &__printRng (ostream& os, IT bg, IT ed) {
    for (IT it=bg; it!=ed; it++) {
        if (it == bg) os << "{" << *it;
        else os << "," << *it;
    }
    return os << "}";
}
template<typename T> ostream &operator << (ostream& os, const vector<T> &vec) {
    return __printRng(os,ALL(vec));
}
#else
#define debug(...)
#endif
#include "friend.h"

// Find out best sample

const int MAXN = 100005;
vector<int> edge[MAXN];
void add_edge (int u, int v) {
    edge[u].eb(v);
    edge[v].eb(u);
}

bool vis[MAXN];
void dfs (int nd, int &x, int &y, int &bg, int *cf, int c=0) {
    bg = max(bg, cf[nd]);
    if (c) x += cf[nd];
    else y += cf[nd];
    vis[nd] = true;
    for (auto v : edge[nd]) {
        if (!vis[v]) {
            dfs(v, x, y, bg, cf, c^1);
        }
    }
}
int findSample(int n,int confidence[],int host[],int p[]){
    bool fc = false;
    for (int i=1; i<n; i++) {
        if (p[i] == 0) {
            add_edge(i, host[i]);
        } else if (p[i] == 1) {
            for (auto v : edge[host[i]]) {
                add_edge(v, i);
            }
        } else {
            for (auto v : edge[host[i]]) {
                add_edge(v, i);
            }
            add_edge(i, host[i]);
            fc = true;
        }
    }

    int ans = 0;
    int sz = 0;
    for (int i=0; i<n; i++) {
        if (!vis[i]) {
            int x = 0, y = 0, bg = 0;
            dfs(i, x, y, bg, confidence, 0);
            ans += max(x, y);
            sz+=bg;
        }
    }
    return fc ? sz : ans;

}
#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...