Submission #1108052

#TimeUsernameProblemLanguageResultExecution timeMemory
1108052kiethm07Bitaro’s Party (JOI18_bitaro)C++11
0 / 100
2 ms6224 KiB
#include <bits/stdc++.h> #define pii pair<int,int> #define iii pair<int,pii> #define fi first #define se second #define vi vector<int> #define all(x) x.begin(),x.end() #define TEXT "a" using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int inf = 1e9 + 7; const ld eps = 1e-8; const double pi = acos(-1); const int N = 1e5 + 5; const int BLOCK = 1005; vector<int> a[N]; bool del[N]; int n,m,q; int dp[N]; bool used[N]; pair<int,int> f[N][BLOCK]; int sz[N]; int cal(int u){ if (dp[u] != -inf) return dp[u]; dp[u] = del[u] ? -1 : 0; for (int v : a[u]){ int f = cal(v); if (f != -1) dp[u] = max(dp[u], f + 1); } return dp[u]; } void precompute(){ for (int u = 1; u <= n; u++){ priority_queue<pii> pq; for (int v : a[u]){ for (int i = 0; i < sz[v]; i++) pq.push(f[v][i]); } vector<int> tmp; while(!pq.empty() && sz[u] < BLOCK){ pii t = pq.top(); pq.pop(); if (t.fi == -1) break; if (used[t.se] == 0){ used[t.se] = 1; tmp.push_back(t.se); } else continue; t.fi++; f[u][sz[u]++] = t; } if (sz[u] < BLOCK) f[u][sz[u]++] = pii(0,u); for (int i : tmp) used[i] = 0; } } void heavy(int str, vector<int>& v){ for (int i = 1; i <= n; i++) dp[i] = -inf; for (int i : v) del[i] = 1; cout << cal(str) << "\n"; for (int i : v) del[i] = 0; } void light(int str, vector<int>& v){ int i = 0; while(i < v.size() && i < sz[str] && f[str][i].se == v[i]) i++; int res = i < sz[str] ? f[str][i].fi : -1; cout << res << "\n"; } int main(){ cin.tie(0) -> sync_with_stdio(0); if (fopen(TEXT".inp","r")){ freopen(TEXT".inp","r",stdin); freopen(TEXT".out","w",stdout); } cin >> n >> m >> q; for (int i = 1; i <= m; i++){ int u,v; cin >> u >> v; a[v].push_back(u); } precompute(); for (int u = 1; u <= n; u++) cout << u << " " << sz[u] << "\n"; while(q--){ int str; cin >> str; int num; cin >> num; vector<int> v(num); for (int& i : v) cin >> i; if (v.size() >= BLOCK) heavy(str,v); else light(str,v); } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void light(int, std::vector<int>&)':
bitaro.cpp:76:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     while(i < v.size() && i < sz[str] && f[str][i].se == v[i]) i++;
      |           ~~^~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(TEXT".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(TEXT".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...