Submission #724916

#TimeUsernameProblemLanguageResultExecution timeMemory
724916CookieBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2065 ms11428 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("WINTER.inp"); ofstream fout("WINTER.out"); #define ll long long #define int long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; const ll mod = 1e9 + 7; const int mxn = 1e5, mxm = 2e5; const int sq = 301; pii dp[mxn + 1][sq + 1]; int dp2[mxn + 1], x[mxn + 1]; vt<int>adj[mxn + 1]; bool no[mxn + 1]; int n, m, q; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; forr(i, 0, m){ int u, v; cin >> u >> v; adj[v].pb(u); } for(int i = 1; i <= n; i++){ for(int j = 0; j < sq; j++){ dp[i][j] = make_pair(-1, -1); } } dp[1][0] = make_pair(0, 1); for(int i = 2; i <= n; i++){ for(auto j: adj[i]){ vt<pii>v; for(int k = 0; k < sq; k++){ v.pb(dp[i][k]); if(dp[j][k].fi != -1)v.pb(make_pair(dp[j][k].fi + 1, dp[j][k].se)); } sort(v.rbegin(), v.rend()); for(int k = 0; k < sq; k++)dp[i][k] = v[k]; } for(int j = 0; j < sq; j++){ if(dp[i][j].first == -1){ dp[i][j] = make_pair(0, i); break; } } } forr(i, 0, q){ int t, y; cin >> t >> y; forr(j, 0, y){ cin >> x[j]; no[x[j]] = 1; } if(y < sq){ int ans = -1; for(int j = 0; j < sq; j++){ if(dp[t][j].second == -1 || !no[dp[t][j].second]){ ans = dp[t][j].first; break; } } cout << ans << "\n"; }else{ forr(j, 1, t + 1)dp2[j] = -1; for(int j = 1; j <= t; j++){ if(!no[j])dp2[j] = 0; for(auto k: adj[j]){ if(dp2[k] != -1){ dp2[j] = max(dp2[j], dp2[k] + 1); } } } cout << dp2[t] << "\n"; } forr(j, 0, y)no[x[j]] = 0; } return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...