제출 #884172

#제출 시각아이디문제언어결과실행 시간메모리
884172OAleksaBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2057 ms25832 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, cnt[N], d[N]; vector<int> g[N], in[N]; vector<pair<int, int>> dis[N]; 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); } for (int i = 1;i <= n;i++) { vector<pair<int, int>> t; t.push_back({i, 0}); for (auto u : in[i]) { for (auto x : dis[u]) t.push_back({x.f, x.s + 1}); } sort(t.begin(), t.end(), [&](pair<int, int> x, pair<int, int> y) { return x.s > y.s; }); for (int j = 0;j < min(B + 10, (int)t.size());j++) dis[i].push_back(t[j]); } 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 < B) { for (auto u : dis[s]) { if (!cnt[u.f]) ans = max(ans, u.s); } } else { for (int i = 1;i <= n;i++) d[i] = -1; 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...