Submission #1251890

#TimeUsernameProblemLanguageResultExecution timeMemory
1251890tkm_algorithmsBitaro’s Party (JOI18_bitaro)C++20
100 / 100
798 ms111244 KiB
/** * In the name of Allah * We are nothing and you're everything * Ya Muhammad! **/ #include <bits/stdc++.h> #ifdef LOCAL #define debug(x) cerr << #x << "= " << x << endl; #else #define debug(x) #endif using namespace std; using ll = long long; using ull = uint64_t; #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define mp(x, y) make_pair(x, y) #define pii pair<int, int> //#define int long long const char nl = '\n'; const int N = 1e5+5; const int inf = 1e9; vector<int> g[N], ind(N); vector<pii> v[N]; vector<bool> vis(N, false); const int bl = 100; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; g[b].push_back(a); } for (int i = 1; i <= n; ++i) { priority_queue<pii> pq; for (auto j: g[i]) pq.push(mp(v[j][0].first, j)); while (!pq.empty() && sz(v[i])<bl) { auto [d, x] = pq.top(); pq.pop(); int y = v[x][ind[x]].second; if (!vis[y]) { vis[y] = true; v[i].push_back(mp(d+1, y)); } ind[x] += 1; if (ind[x] < sz(v[x]))pq.push(mp(v[x][ind[x]].first, x)); } if (sz(v[i])<bl)v[i].push_back(mp(0, i)); for (auto j: v[i])vis[j.second] = false; for (auto j: g[i])ind[j] = 0; } vector<bool> was(n+1); for (; q>0; --q) { int t, y; cin >> t >> y; vector<int> c(y); for (auto &i: c) { cin >> i; was[i] = true; } bool ok = false; for (auto j: v[t]) if (!was[j.second]) { cout << j.first << nl; ok = true; break; } if (!ok) { vector<int> dp(n+1, -1); for (int i = 1; i <= n; ++i)if (!was[i])dp[i] = 0; for (int i = 1; i <= n; ++i) for (auto j: g[i]) if (~dp[j])dp[i] = max(dp[i], dp[j]+1); cout << dp[t] << nl; } for (auto i: c)was[i] = 0; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...