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>
#define int long long int
#define ff first
#define ss second
#define FT ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int n , m , q;
const int maxn = 1e5 + 10;
vector <int> adj[maxn];
int dp[maxn];
bool mark[maxn];
void dfs (int v)
{
for (auto u : adj[v])
{
dfs (u);
dp[v] = max (dp[v] , dp[u] + 1);
}
}
signed main()
{
FT;
cin >> n >> m >> q;
for (int i = 1 ; i <= m ; i++)
{
int s , e;
cin >> s >> e;
adj[e].push_back(s);
}
for (int i = 1 ; i <= n ; i++)
{
dp[i] = -1;
}
while (q--)
{
int t , y;
cin >> t >> y;
while (y--)
{
int c;
cin >> c;
mark[c] = true;
}
dfs (t);
int ans = 0;
for (int i = 1 ; i <= n ; i++)
{
if (!mark[i])
{
ans = max (ans , dp[i]);
}
}
cout << ans << "\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... |