제출 #285647

#제출 시각아이디문제언어결과실행 시간메모리
285647ToMmyDong친구 (IOI14_friend)C++11
23 / 100
8 ms1280 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 = 1003;
vector<int> edge[MAXN];
void add_edge (int u, int v) {
    edge[u].eb(v);
    edge[v].eb(u);
}

bool vis[MAXN];


vector<int> xs, ys;
void dfs (int nd, int c) { 
    if (c) xs.eb(nd);
    else ys.eb(nd);
    vis[nd] = true;
    for (auto v : edge[nd]) {
        if (!vis[v]) {
            dfs(v, c^1);
        }
    }
}

int yp[MAXN];
bool mat (int nd) {
    if (vis[nd]) return false;
    vis[nd] = true;
    for (int u : edge[nd]) {
        if (yp[u] == -1 || mat(yp[u])) {
            yp[u] = nd;
            return true;
        }
    }
    return false;
}


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;
        }
    }

    for (int i=0; i<n; i++) {
        if (!vis[i]) {
            dfs(i, 0);
        }
    }

    memset(vis, 0, sizeof(vis));
    memset(yp, -1, sizeof(yp));
    int ans = 0;
    for (int i : xs) {
        if (!vis[i]) {
            memset(vis, 0, sizeof(vis));
            ans += mat(i);
        }
    }

    return n - ans;

}

컴파일 시 표준 에러 (stderr) 메시지

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:68:10: warning: variable 'fc' set but not used [-Wunused-but-set-variable]
   68 |     bool fc = false;
      |          ^~
#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...