답안 #128947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128947 2019-07-11T11:08:03 Z TAISA_ Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
3 ms 656 KB
#include "grader.h"
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
vector<vector<int>> G(512);
vector<int> v, vis(512);
void dfs(int i, int p) {
    v.push_back(i);
    for (auto &e : G[i]) {
        if (e == p) {
            continue;
        }
        dfs(e, i);
        v.push_back(i);
    }
}
int findEgg(int N, vector<pair<int, int>> bridges) {
    for (int i = 0; i < 512; i++) {
        G[i].clear();
        vis[i] = 0;
    }
    v.clear();
    for (int i = 0; i < N - 1; i++) {
        bridges[i].first--;
        bridges[i].second--;
        G[bridges[i].first].push_back(bridges[i].second);
        G[bridges[i].second].push_back(bridges[i].first);
    }
    dfs(0, -1);
    int l = 0, r = v.size();
    int t = N;
    vector<int> to;
    set<int> st;
    while (1) {
        if (t == 1) {
            for (int i = l; i < r; i++) {
                if (!vis[v[i]]) {
                    return v[i] + 1;
                }
            }
        }
        // cout << l << " " << r << " " << t << endl;
        int m = l;
        st.clear();
        for (int i = l; i < r; i++) {
            if (!vis[v[i]]) {
                st.insert(v[i]);
                if (st.size() >= t / 2) {
                    m = i;
                    break;
                }
            }
        }
        to.clear();
        for (int i = l; i <= m; i++) {
            to.push_back(v[i]);
        }
        if (query(to)) {
            for (int i = 0; i < N; i++) {
                if (!st.count(i) && !vis[i]) {
                    vis[i] = 1;
                    t--;
                }
            }
            r = m + 1;
        } else {
            for (int i = 0; i < N; i++) {
                if (st.count(i) && !vis[i]) {
                    vis[i] = 1;
                    t--;
                }
            }
            l = m + 1;
        }
    }
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:88:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (st.size() >= t / 2) {
                     ~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 424 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 568 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 656 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -