Submission #1157113

#TimeUsernameProblemLanguageResultExecution timeMemory
1157113MPGBitaro’s Party (JOI18_bitaro)C++20
7 / 100
1713 ms539648 KiB
//#pragma GCC optomize("Ofast") #pragma GCC optimize("unroll-loops") //#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC target("sse,sse2,sse4.1,sse4.2") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define max_heap priority_queue<pair <ll, pair <ll, ll>>> #define min_heap priority_queue<pair <ll, ll>, vector<pair <ll, ll>>, greater<pair <ll, ll>>> //#define min_heap priority_queue<ll, vector<ll>, greater<ll>> #define sariE cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); #define filE freopen("in.txt", "r", stdin); freopen("out1.txt", "w", stdout); #define endl '\n' #define md(a) (a % mod + mod) % mod #define pb push_back //cout << vectorprecision(5) << fixed << f; //hash prime = 769 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll const maxn = 2e5 + 123; ll const inf = 2e18; ll const loG = 23; ll const mod = 1e9 + 7; //ll const mod = 998244353; ll const sq = 500; ll power(ll a, ll b, ll mod){if(b==0)return 1;if(b==1)return a;ll x = power(a, b / 2, mod);return (((x * x) % mod) * (b % 2 ? a : 1)) % mod;} ll n, m, q, mx[maxn], dp[maxn]; vector <ll> g[maxn]; vector <pair <ll, ll>> tool[maxn]; bool mark[maxn]; void Solve(){ cin >> n >> m >> q; for (int i = 1; i < m + 1; i++){ ll a, b; cin >> a >> b; g[b].pb(a); } tool[1].pb({0, 1}); for (int i = 1; i < n + 1; i++) mx[i] = -inf; for (int i = 2; i < n + 1; i++){ vector <ll> tmp; tmp.clear(); for (ll u : g[i]){ for (auto p : tool[u]){ mx[p.second] = max(mx[p.second], p.first + 1); if (!mark[p.second]){ tmp.pb(p.second); mark[p.second] = 1; } } } vector <pair <ll, ll>> st; st.clear(); for (ll x : tmp){ st.pb({mx[x], x}); mark[x] = 0; mx[x] = -inf; } st.pb({0, i}); //cout << i << ' ' << st.size() << endl; sort(st.begin(), st.end()); ll cnt = 0; for (int j = st.size() - 1; (j > -1 && cnt <= sq); j--){ cnt++; tool[i].pb({st[j].first, st[j].second}); } } // for (int i = 2; i < n + 1; i++){ // cout << i << " :: " << endl; // for (auto p : tool[i]) // cout << p.first << ' ' << p.second << endl; // } while (q--){ ll v, t; cin >> v >> t; vector <ll> tmp; tmp.clear(); for (int i = 1; i < t + 1; i++){ ll x; cin >> x; tmp.pb(x); mark[x] = 1; } if (t >= sq){ for (int i = 1; i < v + 1; i++){ dp[i] = -inf; if (!mark[i]) dp[i] = 0; for (ll u : g[i]) dp[i] = max(dp[i], dp[u] + 1); } cout << (dp[v] < 0 ? -1 : dp[v]) << endl; } else{ ll ans = -inf; for (auto p : tool[v]){ if (!mark[p.second]) ans = max(ans, p.first); } cout << (ans < 0 ? -1 : ans) << endl; } for (ll x : tmp) mark[x] = 0; } } int main(){ sariE;// filE; int test = 1; //cin >> test; while (test--) Solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...