Submission #1126647

#TimeUsernameProblemLanguageResultExecution timeMemory
1126647Mikael639Bitaro’s Party (JOI18_bitaro)C++20
7 / 100
1132 ms589824 KiB
#include <bits/stdc++.h> #define fi first #define se second #define For(i, a, b) for (int i = (a); i <= (b); ++i) #define ForD(i, a, b) for (int i = (a); i >= (b); --i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define repD(i, n) for (int i = (n) - 1; i >= 0; --i) #define coutE(x) {cout << x << '\n'; return;} #define pb push_back #define pf push_front #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define bs binary_search #define ub upper_bound #define lb lower_bound #define endl '\n' #define db long double #define ll long long #define ii pair<int, int> #define vi vector<int> #define vii vector<ii> #define int long long using namespace std; void file(string s){ if (s.empty()) return; freopen((s + ".inp").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } template <class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return 1; } return 0; } template <class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return 1; } return 0; } mt19937_64 rng(time(0)); const int N = 1e6 + 5; const int B = 120; const int MOD = 1e9 + 7; //998244353; const int INF = 1e9; const long long LINF = 1e18; const int dx[] = {1, 0, 0, -1}; const int dy[] = {0, 1, -1, 0}; int n, m, q, busy_pussy[N]; vi g[N]; bool seen[N], busy[N]; int dp[N]; set<ii, greater<>> st[N]; void dfs(int u, bool mark){ seen[u] = 1; dp[u] = busy[u] ? -INF : 0; if (mark) st[u].insert({0, u}); for (int v: g[u]){ if (!seen[v]) dfs(v, mark); maximize(dp[u], dp[v] + 1); if (!mark) continue; for (ii p: st[v]){ ++p.fi; if (sz(st[u]) < B) st[u].insert(p); else{ if (st[u].begin()->fi >= p.fi) break; st[u].erase(st[u].begin()); st[u].insert(p); } } } } void solve(){ cin >> n >> m >> q; rep(i, m){ int u, v; cin >> u >> v; g[v].pb(u); } ForD(i, n, 1) if (!seen[i]) dfs(i, 1); while (q--){ int u, k; cin >> u >> k; int cnt = 0; rep(i, k){ cin >> busy_pussy[i]; if (busy_pussy[i] > u) continue; ++cnt; busy[busy_pussy[i]] = 1; } if (cnt < sz(st[u])){ bool ok = 0; for (auto [d, v]: st[u]) if (!busy[v]){ cout << d << '\n'; ok = 1; break; } if (!ok) cout << -1 << '\n'; } else{ memset(seen, 0, sizeof seen); dfs(u, 0); cout << (dp[u] >= 0 ? dp[u] : -1) << '\n'; } rep(i, k) busy[busy_pussy[i]] = 0; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); file(""); int T = 1; //cin >> T; while (T--) solve(); return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void file(std::string)':
bitaro.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen((s + ".inp").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...