제출 #884019

#제출 시각아이디문제언어결과실행 시간메모리
884019OAleksaBitaro’s Party (JOI18_bitaro)C++14
0 / 100
3 ms12892 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define int long long const int N = 1e5 + 69; const int B = 320; int n, m, q, deg[N], cnt[N], dp[N], deg1[N], d[N]; vector<int> g[N], in[N]; set<pair<int, int>> bst[N]; vector<int> dis[2 * B]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n >> m >> q; for (int i = 1;i <= m;i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); g[a].push_back(b); in[b].push_back(a); deg[b]++; deg1[b]++; } queue<int> que; vector<int> p; for (int i = 1;i <= n;i++) { if (deg[i] == 0) { que.push(i); } } while (!que.empty()) { auto v = que.front(); que.pop(); for (auto u : g[v]) { --deg[u]; dp[u] = max(dp[u], dp[v] + 1); que.push(u); } } vector<int> t(n); iota(t.begin(), t.end(), 1); sort(t.begin(), t.end(), [&](int i, int j) { return dp[i] < dp[j]; }); for (int i = 0;i < min(2 * B, n);i++) { p.push_back(t[i]); } sort(p.begin(), p.end()); for (int j = 0;j < (int)p.size();j++) { for (int i = 1;i <= n;i++) dp[i] = 0, deg[i] = deg1[i]; que.push(p[j]); while (!que.empty()) { auto v = que.front(); que.pop(); for (auto u : g[v]) { --deg[u]; dp[u] = max(dp[u], dp[v] + 1); if (deg[u] == 0) que.push(u); } } for (int i = 1;i <= n;i++) dis[j].push_back(dp[i]); } while (q--) { int s, c; cin >> s >> c; int a[c]; for (int i = 0;i < c;i++) { cin >> a[i]; cnt[a[i]] = 1; } int ans = -cnt[s]; if (c < (int)p.size()) { sort(a, a + c); for (int i = 0;i < (int)p.size();i++) { auto u = lower_bound(a, a + c, p[i]) - a; if (u == c || a[u] != p[i]) ans = max(ans, dis[i][s - 1]); } } else { for (int i = 1;i <= n;i++) { d[i] = -1; cnt[i] = 0; } d[s] = 0; for (int i = s;i >= 1;i--) { if (d[i] >= 0) { if (!cnt[i]) ans = max(ans, d[i]); for (auto u : in[i]) { d[u] = max(d[u], d[i] + 1); } } } } cout << ans << '\n'; for (int i = 0;i < c;i++) cnt[a[i]] = 0; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...