제출 #881272

#제출 시각아이디문제언어결과실행 시간메모리
881272bobbilykingBitaro’s Party (JOI18_bitaro)C++17
7 / 100
1905 ms524288 KiB
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include<math.h> using namespace std; typedef int ll; typedef long double ld; typedef pair<ll, ll> pl; typedef vector<ll> vl; #define FD(i, r, l) for(ll i = r; i > (l); --i) #define K first #define V second #define G(x) ll x; cin >> x; #define GD(x) ld x; cin >> x; #define GS(s) string s; cin >> s; #define EX(x) { cout << x << '\n'; exit(0); } #define A(a) (a).begin(), (a).end() #define F(i, l, r) for (ll i = l; i < (r); ++i) #define NN 100010 #define M 1000000007 // 998244353 vector<ll> adj[NN]; ll n; vector<ll> topo; bool bad[NN]; constexpr ll SN = 350; vector<pl> dp[NN]; // only keep up to sqrt(N) things in here int main(){ // freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); cin >> n; G(m) G(q) while (m--) { G(s) G(e) adj[e].push_back(s); } { bool vis[NN] = {}; vector<ll> temp; auto dfs = [&](auto&& self, ll i) -> void { if (vis[i]) return; vis[i] = 1; for (auto y: adj[i]) self(self, y); temp.push_back(i); }; F(i, 1, n+1) if (!vis[i]) { temp.clear(); dfs(dfs, i); topo.insert(topo.end(), temp.rbegin(), temp.rend()); } } for (auto x: topo) { dp[x].emplace_back(0, x); for (auto y: adj[x]) { for (auto z: dp[y]) dp[x].emplace_back(z.K+1, z.V); sort(A(dp[x]), greater()); while (dp[x].size() > SN) dp[x].pop_back(); } } while (q--) { G(t) G(m) vector<ll> v(m); for (auto &x: v) { cin >> x; bad[x]=1; } if (m >= SN) { ll dp[NN] = {}; for (auto x: v) dp[x] = -1e9; for (auto x: topo) { for (auto y: adj[x]) dp[x] = max(dp[x], 1 + dp[y]); } cout << (dp[t] < 0 ? -1: dp[t]) << '\n'; } else { ll ans = -1; for (auto [dist, node]: dp[t]) if (!bad[node]) ans = max(ans, dist); cout << ans << '\n'; } for (auto x: v) bad[x] = 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...