#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int n, m, q;
vector<int> dist(N, - 1);
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> q;
for(int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
if(u > v) {
swap(u, v);
}
adj[v].push_back(u);
}
while(q--) {
int t;
cin >> t;
int s;
cin >> s;
if(s == n) {
cout << - 1 << "\n";
continue;
}
vector<int> Q(n + 1, 0);
while(s--) {
int x;
cin >> x;
Q[x] = 1;
}
dist[t] = 0;
for(int i = t; i >= 1; i--) {
for(auto it : adj[i]) {
dist[it] = max(dist[it], dist[i] + 1);
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
if(dist[i] != - 1) {
if(Q[i]) {
continue;
}
ans = max(ans, dist[i]);
}
}
cout << ans << "\n";
for(int i = 1; i <= n; i++) {
dist[i] = - 1;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |