Submission #1124415

#TimeUsernameProblemLanguageResultExecution timeMemory
1124415Yang8onBitaro’s Party (JOI18_bitaro)C++20
0 / 100
4 ms4928 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; int a[maxn], mx[maxn]; bool dd[maxn], dd2[maxn]; vector<int> o[maxn]; vector<pii> dp[maxn]; void cb(vector<pii>& A, vector<pii>& B, int v) { A.push_back({ 1, v }); for(auto [x, rt] : B) A.push_back({ x + 1, rt }); if(A.size() > can) { sort( all(A), greater<pii>() ); while(A.size() > can) A.pop_back(); } } void dfs(int u) { dd[u] = 1; for(int v : o[u]) { if(!dd[v]) dfs(v); cb(dp[u], dp[v], v); } } int calc(int u) { if(dd2[u]) return mx[u]; for(int v : o[u]) { mx[u] = max(mx[u], calc(v) + 1); } return mx[u]; } void solve() { cin >> n >> m >> Q; fi(i, 1, m) { int u, v; cin >> u >> v; o[v].push_back(u); } fi(i, 1, n) if(!dd[i]) { dfs(i); } fi(i, 1, n) dd[i] = 0, sort( all(dp[i]), greater<pii>() ); fi(i, 1, Q) { int u, k; cin >> u >> k; fi(j, 1, k) cin >> a[j], dd[ a[j] ] = 1; if(k < can) { int ans = 0; for(auto [len, v] : dp[u]) { if(!dd[v]) { ans = len; break; } } cout << ( ans <= 0 ? -1 : ans ) << '\n'; } else { fi(i, 1, n) { mx[i] = dd2[i] = 0; if(dd[i]) mx[i] = -inf; } int ans = calc(u); cout << ( ans <= 0 ? -1 : ans ) << '\n'; } fi(j, 1, k) dd[ a[j] ] = 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...