제출 #778426

#제출 시각아이디문제언어결과실행 시간메모리
778426borisAngelovBitaro’s Party (JOI18_bitaro)C++17
14 / 100
2060 ms9100 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, m, q; vector<int> g[maxn]; bool bad[maxn]; int dp[maxn]; int calc(int node) { dp[node] = 0; for (int i = node - 1; i >= 1; --i) { for (auto prv : g[i]) { if (dp[prv] != -1) { dp[i] = max(dp[i], 1 + dp[prv]); } } } int ans = -1; for (int i = node; i >= 1; --i) { if (bad[i] == false) { ans = max(ans, dp[i]); } } return ans; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> m >> q; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; g[x].push_back(y); } for (int i = 1; i <= q; ++i) { int node, cnt; cin >> node >> cnt; memset(bad, false, sizeof(bad)); memset(dp, -1, sizeof(dp)); for (int j = 1; j <= cnt; ++j) { int next_node; cin >> next_node; bad[next_node] = true; } cout << calc(node) << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...