Submission #1043648

#TimeUsernameProblemLanguageResultExecution timeMemory
1043648khanhtbBitaro’s Party (JOI18_bitaro)C++14
0 / 100
2 ms10584 KiB
#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define pf push_front #define vi vector<ll> #define vii vector<vi> #define pll pair<ll, ll> #define vpll vector<pll> #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; const ll mod = 998244353; const ll inf = 2e18; const ll B = 320; const ll N = 2e5+8; int n,m,q; vector<int> g[N]; vector<pair<int,int>> best[N]; int d[N],vst[N],bad[N],dp[N]; void solve(){ cin >> n >> m >> q; for(int i = 1; i <= m; i++){ int u,v;cin >> u >> v; g[v].pb(u); } for(int u = 1; u <= n; u++){ vector<int> cur; for(int v:g[u]){ for(pair<int,int> ed:best[v]){ int vv = ed.se, w = ed.fi; if(vst[vv] == u) d[vv] = max(d[vv],w+1); else{ vst[vv] = u; d[vv] = w+1; cur.pb(vv); } } } for(int v:cur) best[u].pb({d[v],v}); best[u].pb({0,u}); sort(all(best[u]),greater<pair<int,int>>()); while(best[u].size() > B) best[u].pop_back(); } while(q--){ int t,s;cin >> t >> s; for(int i = 1; i <= s; i++){ int x;cin >> x; bad[x] = q; } if(s < B){ int ans = -1; for(pair<int,int> v:best[t]){ if(bad[v.se] != q){ ans = v.fi; break; } } cout << ans << '\n'; } else{ fill(dp+1,dp+n+1,-1); for(int u = 1; u <= t; u++){ if(bad[u] == q) continue; dp[u] = 0; for(int v:g[u]){ if(dp[v] != -1) dp[u] = max(dp[u],dp[v]+1); } } cout << dp[t] << '\n'; } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll T = 1; // cin >> T; for (ll i = 1; i <= T; i++) { solve(); cout << '\n'; } }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...