답안 #128812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128812 2019-07-11T09:48:03 Z TAISA_ Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
252 ms 131076 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);
    }
};
int n;
vector<vector<int>> G;
vector<int> v, vis;
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) {
    n = N;
    G.resize(N);
    vis.resize(N);
    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;
    while (1) {
        set<int> st;
        int m;
        for (int i = l; i < r; i++) {
            if (!vis[v[i]]) {
                st.insert(v[i]);
                if (st.size() >= t / 2) {
                    m = i;
                    break;
                }
            }
        }
        vector<int> to;
        for (auto it = st.begin(); it != st.end(); it++) {
            to.push_back(*it + 1);
        }
        if (query(to)) {
            for (int i = 0; i < n; i++) {
                if (!st.count(i)) {
                    vis[i] = 1;
                }
            }
            r = m + 1;
            t = to.size();
        } else {
            for (int i = 0; i < n; i++) {
                if (st.count(i)) {
                    vis[i] = 1;
                }
            }
            l = m + 1;
            t -= to.size();
        }
        if (t == 1) {
            for (int i = l; i < r; i++) {
                if (!vis[v[i]]) {
                    return v[i] + 1;
                }
            }
        }
    }
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:78:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (st.size() >= t / 2) {
                     ~~~~~~~~~~^~~~~~~~
eastereggs.cpp:94:15: warning: 'm' may be used uninitialized in this function [-Wmaybe-uninitialized]
             r = m + 1;
             ~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 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 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 252 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -