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;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |