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 ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n, m, q;
ll dis[2009][2009];
vector<ll> inc[2009];
ll nono[2009];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> m >> q;
while(m--){
ll a, b;
cin >> a >> b;
inc[b].pb(a);
}
for(ll i = 1; i <= n; ++i)
for(ll j = 1; j <= n; ++j)
dis[i][j] = -1e9;
for(ll i = 1; i <= n; ++i)
dis[i][i] = 0;
for(ll i = 1; i <= n; ++i)
for(auto u : inc[i])
for(ll j = 1; j <= n; ++j)
if(i != j)
dis[i][j] = max(dis[i][j], 1+dis[u][j]);
while(q--){
ll root;
ll k;
set<ll> tmp;
cin >> root >> k;
while(k--){
ll ttt;
cin >> ttt;
nono[ttt] = 1;
}
ll ans = -1;
for(ll i = 1; i <= n; ++i)
if(!nono[i] && i != root)
ans = max(ans, dis[root][i]);
cout << ans << '\n';
for(ll i = 1; i <= n; ++i)
nono[i] = 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... |