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][MAXN];
int dist[MAXN][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[nod][x.F] = max(dist[nod][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);
}
bool comp[n];
while(Q--){
int a, b; cin >> a >> b;
for(int i = 0; i < b; i++){
int x; cin >> x;
inv[a][x] = 1;
}
int maxi = 0;
if(!comp[a]){
f(a);
comp[a] = 1;
}
for(int i = 1; i <= a; i++){
if(inv[a][i]){
inv[a][i] = 0;
continue;
}
maxi = max(maxi, dist[a][i]);
}
cout << maxi << "\n";
}
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... |