Submission #908785

#TimeUsernameProblemLanguageResultExecution timeMemory
908785BBart888Bitaro’s Party (JOI18_bitaro)C++14
100 / 100
1632 ms497176 KiB
#include <cstdio> #include <iostream> #include <vector> #include <list> #include <string> #include <set> #include <map> #include <algorithm> #include <fstream> #include <cmath> #include <queue> #include <stack> #include <cassert> #include <cstring> #include <climits> #include <functional> #include <cstdlib> #include <complex> #include <array> #include <iomanip> #include <bitset> #define fileIO(name) if(fopen(name".in", "r")) {freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);} using namespace std; const int MAXN = 2e5 + 11; using ll = long long; const int P = 31; const ll mod1 = 1e9 + 7; const ll mod2 = 998244353; using ld = long double; const ld EPS = 1e-5; using pii = pair<int, int>; const int K = 300; int n, m, q; vector<pair<int, int>> good[MAXN]; bool vis[MAXN]; bool bussy[MAXN]; vector<int> adj[MAXN]; vector<int> radj[MAXN]; int dp[MAXN]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); //fileIO("paintbarn"); cin >> n >> m >> q; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); radj[b].push_back(a); } for (int i = 1; i <= n; i++) { for (auto x : radj[i]) { vector<pair<int, int>>fin; good[x].push_back({ 0,x }); int a = 0; int b = 0; int sa = good[x].size(); int sb = good[i].size(); while (fin.size() < K && (a < sa && b < sb)) { if (good[x][a].first + 1 >= good[i][b].first) { fin.push_back({ good[x][a].first + 1, good[x][a].second }); vis[good[x][a].second] = true; a++; } else { fin.push_back({ good[i][b].first, good[i][b].second }); vis[good[i][b].second] = true; b++; } while (a < sa && vis[good[x][a].second]) a++; while (b < sb && vis[good[i][b].second]) b++; } while (fin.size() < K && a < sa) { fin.push_back({ good[x][a].first + 1, good[x][a].second }); vis[good[x][a].second] = true; a++; while (a < sa && vis[good[x][a].second]) a++; } while (fin.size() < K && b < sb) { fin.push_back({ good[i][b].first,good[i][b].second }); vis[good[i][b].second] = true; b++; while (b < sb && vis[good[i][b].second]) b++; } for (auto v : fin) vis[v.second] = false; good[i] = fin; fin.clear(); } } while (q--) { int t, y; cin >> t >> y; vector<int> c(y); for (int i = 0; i < y; i++) { cin >> c[i]; bussy[c[i]] = true; } int ans = -1; if (y < K) { for (auto x : good[t]) { if (!bussy[x.second]) ans = max(ans, x.first); } if (!bussy[t]) ans = max(ans, 0); } else { for (int i = 1; i <= n; i++) dp[i] = -1; dp[t] = 0; if (!bussy[t]) ans = 0; for (int i = t - 1; i; i--) { for (auto x : adj[i]) if (dp[x] != -1) dp[i] = max(dp[i], dp[x] + 1); if (!bussy[i]) ans = max(ans, dp[i]); } } for (int i = 0; i < y; i++) bussy[c[i]] = false; cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...