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 sts stable_sort
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define F first
#define S second
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define eb emplace_back
#define ll long long
#define ui unsigned int
#define ull unsigned long long
using namespace std;
const int MAXN = 1e4 + 4;
const int MOD = 1e9 + 7;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
vector<int> add[MAXN];
bool inv[MAXN];
int dist[MAXN];
void f(int nod){
queue<pair<int, int> > q;
q.push({nod, 0});
while(!q.empty()){
pair<int, int> x = q.front();
q.pop();
if(x.F > nod)continue;
dist[x.F] = max(dist[x.F], x.S);
for(auto &c : add[x.F]){
q.push({c, x.S + 1});
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, Q; cin >> n >> m >> Q;
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
add[b].pb(a);
}
f(n);
while(Q--){
int a, b; cin >> a >> b;
bool c = 0;
for(int i = 0; i < b; i++){
int x; cin >> x;
inv[x] = 1;
}
int maxi = -1;
for(int i = 1; i <= a; i++){
if(inv[i]){
inv[i] = 0;
continue;
}
maxi = max(maxi, dist[i]);
}
if(maxi == -1)cout << maxi << "\n";
else cout << maxi - dist[a] << "\n";
}
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:62:14: warning: unused variable 'c' [-Wunused-variable]
62 | bool c = 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... |