#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 2 * 1e5 + 100, M = 4096 + 10, len = 21, inf = 1e18;
const ll mod = 1000002022;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
vector <int> q[N], rev[N];
bool block[N];
int d[N], b[N], n;
int dj(int x){
set <pii> st;
for(int i = 1; i <= n; i++){
d[i] = -1;
}
d[x] = 0;
int ans = -1;
st.insert({d[x], x});
while((int)st.size() != 0){
int v = st.rbegin()->S;
if(block[v] == false) ans = max(ans, d[v]);
st.erase(--st.end());
for(auto u : rev[v]){
if(d[u] == -1 || d[u] < d[v] + 1){
st.erase({d[u], u});
d[u] = d[v] + 1;
st.insert({d[u], u});
}
}
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int m, g;
cin >> n >> m >> g;
for(int i = 0, a, b; i < m; i++){
cin >> a >> b;
q[a].pb(b);
rev[b].pb(a);
}
for(int i = 0, t, k; i < g; i++){
cin >> t >> k;
for(int j = 0; j < k; j++){
cin >> b[j];
block[b[j]] = true;
}
// calculations
cout << dj(t) << endl;
for(int j = 0; j < k; j++){
block[b[j]] = false;
}
}
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... |