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;
#define endl '\n'
#define pb push_back
#define mk make_pair
#define sz size()
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define kill(x) return cout << x << endl, void();
#define int ll
typedef pair <int, int> pii;
/*
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
*/
const int N = 1e5 + 5;
const int MOD = 998244353, INF = 2e9, MOD2 = 1e9 + 7, sq = 350;
vector <int> adj[N];
int ans;
int h[N], mrk[N];
void dfs (int v)
{
if (!mrk[v])
ans = max (ans, h[v]);
for (int u : adj[v])
{
h[u] = h[v] + 1;
dfs (u);
}
}
void Solve ()
{
int n, m, q, v, u, t, y;
cin >> n >> m >> q;
for (int i = 0; i < m; i++)
{
cin >> v >> u;
v--, u--;
adj[u].pb (v);
}
while (q--)
{
cin >> t >> y;
t--;
ans = -1;
h[t] = 0;
for (int i = 0; i < n; i++)
mrk[i] = 0;
for (int i = 0; i < y; i++)
{
cin >> v;
v--;
mrk[v] = 1;
}
dfs (t);
cout << ans << endl;
}
}
int32_t main ()
{
ios::sync_with_stdio (0), cin.tie (0), cout.tie (0);
int tt = 1;
// cin >> tt;
while (tt--)
Solve ();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |