Submission #646838

#TimeUsernameProblemLanguageResultExecution timeMemory
646838tvladm2009Bitaro’s Party (JOI18_bitaro)C++14
14 / 100
2077 ms149100 KiB
#include <bits/stdc++.h> using ll = long long; int const nmax = 100000; int dp[1 + nmax]; std::vector<int> g[1 + nmax]; std::vector<std::pair<int, int>> sol[1 + nmax]; bool viz[1 + nmax], b[1 + nmax]; int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); for(int i = 1;i <= m; i++) { int u, v; scanf("%d%d", &u, &v); g[u].push_back(v); } for(int i = 1;i <= n; i++) sol[i].push_back({0, i}); for(int u = 1;u <= n; u++) { std::sort(sol[u].rbegin(), sol[u].rend()); for(auto p : sol[u]) viz[p.second] = false; std::vector<std::pair<int, int>> aux; for(auto v : sol[u]) { if(aux.size() >= 120) break; if(!viz[v.second]) { aux.push_back(v); viz[v.second] = 1; } } std::swap(sol[u], aux); for(int v : g[u]) { for(auto p : sol[u]) sol[v].push_back({p.first + 1, p.second}); } } while(q--) { int to, y; std::cin >> to >> y; std::vector<int> c(y + 1); for(int i = 1;i <= y; i++) { int v; std::cin >> v; c[i] = v; b[v] = true; } if(y >= 120) { for(int i = 1;i <= n; i++) { if(b[i]) dp[i] = -1; else dp[i] = 0; } for(int i = 1;i <= n; i++) { if(dp[i] == -1) continue; for(int u : g[i]) dp[u] = std::max(dp[u], dp[i] + 1); } printf("%d\n", dp[to]); } else { int ans = -1; for(auto p : sol[to]) { if(!b[p.second]) ans = std::max(ans, p.first); } printf("%d\n", ans); } for(int i = 1;i <= y; i++) b[c[i]] = false; } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d%d%d", &n, &m, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d%d", &u, &v);
      |     ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...