Submission #1323612

#TimeUsernameProblemLanguageResultExecution timeMemory
1323612adscodingBitaro’s Party (JOI18_bitaro)C++20
14 / 100
557 ms223596 KiB
#include <bits/stdc++.h> #define fi first #define se second #define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i) #define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i) #define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i) #define all(x) x.begin(), x.end() #define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end()) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__) template<typename T> void __prine_one(const char *&s, const T &x) { while (*s == ' ') ++s; const char *p = s; int bal = 0; while (*s) { if (*s == '(') ++bal; else if (*s == ')') --bal; else if (*s == ',' && bal == 0) break; ++s; } cerr.write(p, s - p) << " = " << x; if (*s == ',') { cerr << " , "; ++s; } } template<typename... Args> void debug(const char *s, Args... args) { cerr << "[ "; int dummy[] = {0, (__prine_one(s, args), 0)...}; (void)dummy; cerr << " ]\n\n"; } template<class X, class Y> bool maximize(const X &a, const X &b) { if (a < b) { a = b; return true; } return false; } template<class X, class Y> bool minimize(const X &a, const X &b) { if (a > b) { a = b; return true; } return false; } // -------------------------------------------------------------------------------------------- const int maxn = 1e5 + 3, B = 201; int n, m, q; vector<int> g[maxn], rg[maxn]; // -------------------------------------------------------------------------------------------- namespace AC { bool vis[maxn]; vector<pii> dp[maxn]; int DP[maxn]; vector<int> topo; void dfs_topo(int u) { vis[u] = 1; for (int v : g[u]) if (!vis[v]) dfs_topo(v); topo.push_back(u); } void solve() { FOR(i, 1, n) { if (vis[i]) continue; dfs_topo(i); } reverse(all(topo)); for (int u : topo) { priority_queue<pair<pii, pii>> pq; FOR(i, 0, (int)rg[u].size() - 1) { int v = rg[u][i]; if (dp[v].empty()) continue; pq.push({dp[v][0], {v, 0}}); } int CNT = B; while (CNT && pq.size()) { auto Top = pq.top(); pq.pop(); --CNT; dp[u].push_back({Top.fi.fi + 1, Top.fi.se}); auto nxt = Top.se; if (nxt.se < dp[nxt.fi].size() - 1) { pq.push({dp[nxt.fi][nxt.se + 1], {nxt.fi, nxt.se + 1}}); } } if (dp[u].size() < B) dp[u].push_back({0, u}); } FOR(i, 1, n) vis[i] = 0; while (q--) { int src, k; cin >> src >> k; vector<int> vec; FOR(i, 1, k) { int x; cin >> x; vec.push_back(x); vis[x] = 1; } if (k < B) { // cerr << "TYPE1\n"; int res = -1; for (auto &p : dp[src]) { // dbg(p.se); if (!vis[p.se]) { res = max(res, p.fi); break; } } cout << res << '\n'; } else { // cerr << "TYPE2\n"; FOR(i, 1, n) { DP[i] = vis[i] ? -1 : 0; } for (int u : topo) { if (DP[u] == -1) continue; if (u == src) break; for (int v : g[u]) { DP[v] = max(DP[v], DP[u] + 1); } } cout << DP[src] << '\n'; } for (int x : vec) vis[x] = 0; } } } void solve() { cin >> n >> m >> q; FOR(i, 1, m) { int u, v; cin >> u >> v; g[u].push_back(v); rg[v].push_back(u); } AC :: solve(); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define TASK "TEST" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:206:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  206 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:207:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  207 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...