Submission #201424

#TimeUsernameProblemLanguageResultExecution timeMemory
201424egekabasBitaro’s Party (JOI18_bitaro)C++14
0 / 100
12 ms9720 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<int, int> pii; typedef pair<ld, ld> pld; ll n, m, q; ll sq = 500; vector<ll> inc[200009]; vector<pll> far[200009]; ll dist[200009]; ll check(vector<ll> & v, ll x){ auto it = lower_bound(v.begin(), v.end(), x); if(it == v.end() || *it != x) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin >> n >> m >> q; while(m--){ ll x, y; cin >> x >> y; inc[y].pb(x); } for(ll i = 1; i <= n; ++i){ far[i].pb({0, i}); for(auto u1 : inc[i]) for(auto u2 : far[u1]) far[i].pb({u2.ff+1, u2.ss}); sort(far[i].begin(), far[i].end(), greater<pll>()); while(far[i].size() > 500) far[i].pop_back(); } while(q--){ ll root, k; cin >> root >> k; vector<ll> busy(k); for(ll i = 0; i < k; ++i) cin >> busy[i]; if(k <= 500){ for(auto u : far[root]) if(check(busy, u.ss)){ cout << u.ff << "\n"; break; } } else{ for(ll i = 1; i < root; ++i) dist[i] = -1e18; dist[root] = 0; ll ans = -1; for(ll i = root; i >= 1; --i){ if(dist[i] > ans && check(busy, i)) ans = dist[i]; for(auto u : inc[i]) dist[u] = max(dist[u], dist[i]+1); } cout << ans << "\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...