Submission #479896

#TimeUsernameProblemLanguageResultExecution timeMemory
479896errayBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1764 ms414216 KiB
// author: erray #include <bits/stdc++.h> using namespace std; template<typename A, typename B> string to_string(const pair<A, B>& p); template<typename A, typename B, typename C> string to_string(const tuple<A, B, C>& t); template<typename A, typename B, typename C, typename D> string to_string(const tuple<A, B, C, D>& t); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char& c) { return string("'") + c + "'"; } string to_string(const char *c) { return to_string(string(c)); } string to_string(const bool& b) { return (b ? "true" : "false"); } string to_string(const vector<bool>& v) { string res = "{"; for (int i = 0; i < (int) v.size(); ++i) { if (i > 0) { res += ", "; } res += to_string(v[i]); } res += "}"; return res; } template<size_t T> string to_string(const bitset<T>& bs) { return bs.to_string(); } template<typename T> string to_string(queue<T> q) { string res = "{"; size_t sz = q.size(); while (sz--) { T cur = q.front(); q.pop(); if ((int) res.size() > 1) { res += ", "; } res += to_string(cur); } res += "}"; return res; } template<typename T, class C> string to_string(priority_queue<T, vector<T>, C> pq) { string res = "{"; while (!pq.empty()) { T cur = pq.top(); pq.pop(); if ((int) res.size() > 1) { res += ", "; } res += to_string(cur); } res += "}"; return res; } template<typename T> string to_string(const T& v) { string res = "{"; for (auto &el : v) { if ((int) res.size() > 1) { res += ", "; } res += to_string(el); } res += "}"; return res; } template<typename A, typename B> string to_string(const pair<A, B>& p) { return '(' + to_string(p.first) + ", " + to_string(p.second) + ')'; } template<typename A, typename B, typename C> string to_string(const tuple<A, B, C>& t) { return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ')'; } template<typename A, typename B, typename C, typename D> string to_string(const tuple<A, B, C, D>& t) { return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ')'; } void debug_out(int size, bool first, string name) { vector<string> tmp = {name}; vector<int> tmp2 = {size, first}; cerr << endl; } constexpr int buffer_size = 255; template<typename Head, typename... Tail> void debug_out(int size, bool first, string name, Head H, Tail... T) { string tmp; int off = 0; while ((!name.empty() && name[0] != ',') || off != 0) { tmp += name[0]; name.erase(name.begin()); char c = tmp.back(); if (c == '{' || c == '(') { ++off; } else if (c == '}' || c == ')'){ --off; } } if (!name.empty()) { name.erase(name.begin()); } if (tmp[0] == ' ') { tmp.erase(tmp.begin()); } string buff = to_string(H); if ((int) buff.size() + size + (int) tmp.size() > buffer_size - 5 && !first) { cerr << '\n'; size = 0; } cerr << '[' << tmp << ": " << buff << "] "; debug_out(((int) buff.size() + size + (int) tmp.size() + 5) % buffer_size, false, name, T...); } #ifdef DEBUG #define debug(...) cerr << "-> ", debug_out(3, true, string(#__VA_ARGS__), __VA_ARGS__) #define here cerr << "-> " << __LINE__ << endl #else #define debug(...) void(37) #define here void(37) #endif int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m >> q; const int SQ = 350; vector<vector<int>> g(n); for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; --x, --y; g[y].push_back(x); } debug(g); vector<vector<pair<int, int>>> mxs(n); vector<bool> vis(n); for (int i = 0; i < n; ++i) { mxs[i].emplace_back(-1, i); for (auto u : g[i]) { vector<pair<int, int>> res; merge(mxs[i].begin(), mxs[i].end(), mxs[u].begin(), mxs[u].end(), back_inserter(res), [&](auto x, auto y) { return x.first > y.first; }); mxs[i].clear(); for (auto p : res) { if (!vis[p.second]) { mxs[i].push_back(p); vis[p.second] = true; } } for (auto p : mxs[i]) { vis[p.second] = false; } mxs[i].resize(min(int(mxs[i].size()), SQ)); } for (auto&[e, source] : mxs[i]) { ++e; } } debug(mxs); vector<bool> in(n, true); while (q--) { int t, s; cin >> t >> s; --t; vector<int> a(s); for (int i = 0; i < s; ++i) { cin >> a[i]; --a[i]; in[a[i]] = false; } if (s >= SQ) { vector<int> ans(n, -1); for (int i = 0; i < n; ++i) { if (in[i]) { ans[i] = 0; } for (auto u : g[i]) { if (ans[u] > -1) { ans[i] = max(ans[i], ans[u] + 1); } } } cout << ans[t] << '\n'; } else { int ans = -1; for (auto[e, sr] : mxs[t]) { if (in[sr]) { ans = e; break; } } cout << ans << '\n'; } for (auto e : a) { in[e] = true; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...