Submission #1124473

#TimeUsernameProblemLanguageResultExecution timeMemory
1124473Yang8onBitaro’s Party (JOI18_bitaro)C++20
100 / 100
667 ms111408 KiB
#include <bits/stdc++.h> #define Y8o "bitaro" #define maxn (int) 1e5 + 5 #define ll long long #define pii pair<int, int> #define gb(i, j) ((i >> j) & 1) #define all(x) x.begin(), x.end() #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define fi(i, a, b) for(int i = a; i <= b; i ++) #define fid(i, a, b) for(int i = a; i >= b; i --) //#define f first //#define s second using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll GetRandom(ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rng); } void iof() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); if(fopen(Y8o".inp", "r")) { freopen(Y8o".inp", "r", stdin); // freopen(Y8o".out", "w", stdout); } } void ctime() { cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; } const int inf = 1e9; const int can = 100; int n, m, Q; vector<int> o[maxn]; int a[maxn], dp2[maxn]; int dd[maxn], mx[maxn]; vector<pii> dp[maxn]; void solve() { cin >> n >> m >> Q; fi(i, 1, m) { int u, v; cin >> u >> v; o[v].push_back(u); } fi(u, 1, n) { vector<int> tmp; tmp.push_back(u), mx[u] = 0; for(int ke : o[u]) for(auto [x, v] : dp[ke]) { if(dd[v] == u) mx[v] = max(mx[v], x + 1); else dd[v] = u, mx[v] = x + 1, tmp.push_back(v); } sort( all(tmp), [](int x, int y) { return mx[x] < mx[y]; }); while(dp[u].size() < can && tmp.size()) { dp[u].push_back({ mx[tmp.back()], tmp.back() }); tmp.pop_back(); } } fi(i ,1, n) dd[i] = 0; fi(_, 1, Q) { int root, k; cin >> root >> k ; fi(i, 1, k) cin >> a[i], dd[ a[i] ] = 1; if(k >= can) { fi(i, 1, n) { dp2[i] = 0; if(dd[i]) dp2[i] = -inf; } fi(u, 1, root) { for(int v : o[u]) { dp2[u] = max(dp2[u], dp2[v] + 1); } } cout << (dp2[root] < 0 ? -1 : dp2[root]) << '\n'; } else { int ans = dd[root] ? -inf : 0; for(auto [x, v] : dp[root]) { if(!dd[v]) { ans = x; break; } } cout << (ans < 0 ? -1 : ans) << '\n'; } fi(i, 1, k) dd[ a[i] ] = 0; } } int main() { iof(); int nTest = 1; // cin >> nTest; while(nTest --) { solve(); } ctime(); return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void iof()':
bitaro.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...