This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//1L1YA
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<pii,pii> piii;
#define Pb push_back
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define al(x,n) x+1,x+n+1
#define SZ(x) ((int)x.size())
#define lc (id<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define dokme(x) cout << x << endl, exit(0)
#define sik(x) cout << x << endl;continue;
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=1e5+11;
const int sq=350;
const int lg=23;
int n,m,q,dp[N];
vector<int> adj[N];
vector<pii> vc[N];
bool mark[N];
void slv(){
for(int v=1;v<=n;v++){
dp[v]=-inf;
if(!mark[v]) dp[v]=0;
for(int u: adj[v]) dp[v]=max(dp[v],dp[u]+1);
}
}
int main(){
FastIO
cin >> n >> m >> q;
for(int i=1;i<=m;i++){
int u,v;
cin >> u >> v;
adj[v].Pb(u);
}
for(int v=1;v<=n;v++){
priority_queue<piii,vector<piii>> pq;
for(int u: adj[v]) pq.push({vc[u][0],{u,0}});
while(SZ(pq) && SZ(vc[v])<sq){
pii p=pq.top().F;p.F++;
int i=pq.top().S.F,ind=pq.top().S.S;
pq.pop();
if(!mark[p.S]) vc[v].Pb(p);
mark[p.S]=1;
ind++;
if(ind!=SZ(vc[i])) pq.push({vc[i][ind],{i,ind}});
}
vc[v].Pb({0,v});
for(pii p: vc[v]) mark[p.S]=0;
}
while(q--){
int v;
cin >> v;
int y;
cin >> y;
vector<int> vec;
for(int j=1;j<=y;j++){
int x;cin >> x;
vec.Pb(x);
mark[x]=1;
}
if(y>=sq){
slv();
cout << max(-1,dp[v]) << endl;
}
else{
bool fl=1;
for(pii p: vc[v])
if(!mark[p.S]){
cout << p.F << endl;
fl=0;
break;
}
if(fl) cout << -1 << endl;
}
for(int x: vec) mark[x]=0;
}
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... |