제출 #158179

#제출 시각아이디문제언어결과실행 시간메모리
158179fedoseevtimofeyBitaro’s Party (JOI18_bitaro)C++14
7 / 100
54 ms4396 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N = 1e3 + 7; const int Inf = 1e9; vector <int> g[N]; vector <int> rg[N]; bool used[N]; int dp[N]; vector <int> ts; void dfs(int u) { used[u] = 1; for (int v : g[u]) { if (!used[v]) { dfs(v); } } ts.push_back(u); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, m, q; cin >> n >> m >> q; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); rg[v].push_back(u); } for (int i = 0; i < n; ++i) { if (!used[i]) { dfs(i); } } while (q--) { int t; cin >> t; --t; vector <int> ban(n); int y; cin >> y; for (int i = 0; i < y; ++i) { int x; cin >> x; --x; ban[x] = 1; } fill(dp, dp + n, -Inf); dp[t] = 0; for (int x : ts) { for (int v : g[x]) { dp[x] = max(dp[x], dp[v] + 1); } } int ans = -1; for (int i = 0; i < n; ++i) if (!ban[i]) ans = max(ans, dp[i]); cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...