Submission #111536

# Submission time Handle Problem Language Result Execution time Memory
111536 2019-05-15T14:51:33 Z TAISA_ Bitaro’s Party (JOI18_bitaro) C++14
0 / 100
2 ms 384 KB
#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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> v, in(n);
    vector<vector<int>> G(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        in[b]++;
    }
    stack<int> st;
    for(int i = 0; i < n; i++) {
        if(in[i] == 0) {
            st.push(i);
        }
    }
    while(!st.empty()) {
        int i = st.top();
        v.push_back(i);
        st.pop();
        for(auto e : G[i]) {
            in[e]--;
            if(in[e] == 0) {
                st.push(e);
            }
        }
    }
    int sq = sqrt(100000);
    auto dp = make_v<int>(n, sq + 1);
    auto idx = make_v<int>(n, sq + 1);
    fill_v(dp, -INF);
    fill_v(idx, -1);
    vector<int> sz(n), vis(n);
    for(int i = 0; i < n; i++) {
        dp[i][0] = 0;
        idx[i][0] = i;
        sz[i] = 1;
    }
    for(auto i : v) {
        for(auto e : G[i]) {
            vector<int> ndp(sq + 1, -INF), nid(sq + 1, -1);
            int a = 0, b = 0, t = 0;
            while(a < sz[i] || b < sz[e]) {
                if(t >= sq) {
                    break;
                }
                if(a >= sz[i]) {
                    ndp[t] = dp[e][b];
                    nid[t] = idx[e][b];
                    b++;
                } else if(b >= sz[i] || dp[i][a] + 1 > dp[e][b]) {
                    ndp[t] = dp[i][a] + 1;
                    nid[t] = idx[i][a];
                    a++;
                } else {
                    ndp[t] = dp[e][b];
                    nid[t] = idx[e][b];
                    b++;
                }
                vis[nid[t]] = 1;
                t++;
            }
            sz[e] = t;
            for(int j = 0; j <= sq; j++) {
                dp[e][j] = ndp[j];
                idx[e][j] = nid[j];
                if(nid[j] >= 0) {
                    vis[nid[j]] = 0;
                }
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            cout << idx[i][j] << " ";
        }
        cout << endl;
    }
    while(q--) {
        int t, y;
        cin >> t >> y;
        --t;
        vector<int> c(y);
        for(int i = 0; i < y; i++) {
            cin >> c[i];
            --c[i];
            vis[c[i]] = 1;
        }
        ll ans = -INF;
        if(y < sq) {
            for(int i = 0; i <= sq; i++) {
                if(!vis[idx[t][i]]) {
                    ans = dp[t][i];
                    break;
                }
            }
        } else {
            vector<int> dp2(n, -INF);
            for(auto i : v) {
                if(!vis[i]) {
                    chmax(dp2[i], 0);
                }
                for(auto e : G[i]) {
                    chmax(dp2[e], dp2[i] + 1);
                }
            }
            ans = dp2[t];
        }
        cout << max(ans, -1LL) << endl;
        for(int i = 0; i < y; i++) {
            vis[c[i]] = 0;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -