제출 #701976

#제출 시각아이디문제언어결과실행 시간메모리
701976CyanmondFriend (IOI14_friend)C++17
0 / 100
1 ms340 KiB
#include "friend.h"
#include <bits/stdc++.h>

int findSample(int n, int confidence[], int host[], int protocol[]) {
    /*
    if (n <= 10) {
        std::vector<std::vector<bool>> isFriend(n, std::vector<bool>(n));
        for (int x = 1; x < n; ++x) {
            const int h = host[x], type = protocol[x];
            if (type == 0) {
                isFriend[h][x] = isFriend[x][h] = true;
            } else if (type == 1) {
                for (int i = 0; i < n; ++i) {
                    if (isFriend[h][i]) {
                        isFriend[i][x] = isFriend[x][i] = true;
                    }
                }
            } else if (type == 2) {
                for (int i = 0; i < n; ++i) {
                    if (isFriend[h][i]) {
                        isFriend[i][x] = isFriend[x][i] = true;
                    }
                }
                isFriend[h][x] = isFriend[x][h] = true;
            }
        }

        int answer = 0;
        for (int bits = 0; bits < (1 << n); ++bits) {
            bool isOk = true;
            for (int i = 0; i < n; ++i) {
                if (not(bits & (1 << i))) {
                    continue;
                }
                for (int j = 0; j < n; ++j) {
                    if (not(bits & (1 << j))) {
                        continue;
                    }
                    if (isFriend[i][j]) {
                        isOk = false;
                    }
                }
            }
            int sum = 0;
            if (isOk) {
                for (int i = 0; i < n; ++i) {
                    if (not(bits & (1 << i))) {
                        continue;
                    }
                    sum += confidence[i];
                }
                answer = std::max(answer, sum);
            }
        }
        return answer;
    }*/

    bool ex0 = false, ex1 = false, ex2 = false;
    for (int i = 1; i < n; ++i) {
        if (protocol[i] == 0) {
            ex0 = true;
        }
        if (protocol[i] == 1) {
            ex1 = true;
        }
        if (protocol[i] == 2) {
            ex2 = true;
        }
    }
    if (ex1 and ex0 and (not ex2)) {
        // not prove
        std::vector<std::vector<bool>> isFriend(n, std::vector<bool>(n));
        for (int x = 1; x < n; ++x) {
            const int h = host[x], type = protocol[x];
            if (type == 0) {
                isFriend[h][x] = isFriend[x][h] = true;
            } else if (type == 1) {
                for (int i = 0; i < n; ++i) {
                    if (isFriend[h][i]) {
                        isFriend[i][x] = isFriend[x][i] = true;
                    }
                }
            }
        }
        std::vector<int> color(n, -1);
        int answer = 0;
        for (int f = 0; f < n; ++f) {
            if (color[f] != -1) {
                continue;
            }
            int a = 0, b = 0;
            auto dfs = [&](auto &&self, const int v, const bool c) -> void {
                if (c) {
                    ++a;
                } else {
                    ++b;
                }
                color[v] = c;
                for (int t = 0; t < n; ++t) {
                    if ((not isFriend[v][t]) or color[t] != -1) {
                        continue;
                    }
                    self(self, t, not c);
                }
            };
            dfs(dfs, f, false);
            answer += std::max(a, b);
        }
        return answer;
    }
    return -1;
}
#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...