Submission #724923

#TimeUsernameProblemLanguageResultExecution timeMemory
724923CookieBitaro’s Party (JOI18_bitaro)C++14
100 / 100
866 ms483956 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(sq + 1); int l = 0, r = 0; for(int k = 0; k < sq;){ if(dp[j][r].first == -1){ if(dp[i][l].se != -1 && x[dp[i][l].se]){ l++; continue; } if(dp[i][l].se != -1)x[dp[i][l].se] = 1; v[k] = dp[i][l]; l++; k++; } else if(dp[i][l].first > dp[j][r].first + 1){ if(dp[i][l].se != -1 && x[dp[i][l].se]){ l++; continue; } if(dp[i][l].se != -1)x[dp[i][l].se] = 1; v[k] = dp[i][l]; l++; k++; }else{ if(dp[j][r].se != -1 && x[dp[j][r].se]){ r++; continue; } if(dp[j][r].se != -1)x[dp[j][r].se] = 1; v[k] = make_pair(dp[j][r].first + 1, dp[j][r].se); r++; k++; } } for(int k = 0; k < sq; k++){ dp[i][k] = v[k]; if(v[k].se != -1)x[v[k].se] = 0; } } 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 - 3){ int ans = -1; bool ok =0; 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); }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:91:18: warning: unused variable 'ok' [-Wunused-variable]
   91 |             bool ok  =0;
      |                  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...