This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |