Submission #198321

#TimeUsernameProblemLanguageResultExecution timeMemory
198321quocnguyen1012Bitaro’s Party (JOI18_bitaro)C++14
0 / 100
776 ms524288 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int maxn = 1e5 + 5, mod = 1e9 + 7, magic = 400; vector<int> adj[maxn]; int N, M, Q; pair<int, int> dist[maxn][magic]; int D[maxn], del[maxn]; bool vis[maxn]; signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } cin >> N >> M >> Q; while (M--){ int u, v; cin >> u >> v; adj[v].pb(u); } vector<int> node; fill_n(&dist[0][0], maxn * magic, mp(-1, -1)); for (int u = 1; u <= N; ++u){ node.clear(); node.pb(u); for (int it : adj[u]){ for (int k = 1; k <= magic; ++k){ if (dist[it][k].fi == -1) continue; int v = dist[it][k].se; D[v] = max(D[v], dist[it][k].fi + 1); if (!vis[v]){ vis[v] = 1; node.pb(v); } } } sort(node.begin(), node.end(), [&](const int & x, const int & y){ return D[x] > D[y]; }); for (int j = 1; j <= magic && j <= (int)node.size(); ++j){ dist[u][j] = mp(D[node[j - 1]], node[j - 1]); } for (auto & v : node) D[v] = vis[v] = 0; } while (Q--){ int u, n; cin >> u >> n; for (int i = 1; i <= n; ++i){ cin >> del[i]; vis[del[i]] = true; } int ret = -2; for (int j = 1; j <= magic; ++j){ if (dist[u][j].fi == -1){ ret = -1; break; } else if (!vis[dist[u][j].se]){ ret = dist[u][j].fi; break; } } if (ret == -2){ ret = -1; if (!vis[u]) ret = 0; for (int i = u - 1; i >= 1; --i){ for (int v : adj[i]){ if (v <= u){ D[v] = max(D[v], D[i] + 1); ret = max(ret, D[v]); } } } for (int i = u; i >= 1; --i){ D[i] = 0; } } for (int i = 1; i <= n; ++i){ vis[del[i]] = false; } cout << ret << '\n'; } }

Compilation message (stderr)

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