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>
using namespace std;
#define fr first
#define sc second
const int mxn=1e5+5,sq=130;
int n,m,q,mark[mxn];
vector<int>v[mxn];
vector<pair<int,int> >pre[mxn];
int main(){
cin>>n>>m>>q;
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
v[y].push_back(x);
}
for(int i=1;i<=n;i++){
int p[v[i].size()],cnt=0;
memset(p,0,sizeof p);
pair<int,int>num;
while(pre[i].size()<sq && cnt<v[i].size()){
for(int j=0;j<v[i].size();j++){
int x=v[i][j];
if(p[j]>=pre[x].size() )continue;
while( p[j]<pre[x].size()&&mark[pre[x][p[j]].fr] )p[j]++;//cout<<j<<" "<<p[j]<<endl;
if(p[j]>=pre[x].size()){
cnt++;
continue;
}
if(pre[x][p[j]].sc+1>=num.sc){
num.sc=pre[x][p[j]].sc+1;
num.fr=pre[x][p[j]].fr;
}
}
if(num.fr==0)break;
mark[num.fr]=1;
pre[i].push_back(num);
num={0,0};
}
if(pre[i].size()<sq)
pre[i].push_back({i,0});
for(auto j:pre[i])
mark[j.fr]=0;
}
while(q--){
int t,y;
cin>>t>>y;
int a[y];
for(int i=0;i<y;i++){
cin>>a[i];
mark[a[i]]=1;
}
if(y>=sq){
int dp[t];
for(int i=1;i<=t;i++){
dp[i]=0;
if(mark[i])continue;
for(auto j:v[i]){
if(!mark[j])dp[i]=max(dp[i],dp[j]+1);
}
}
if(dp[t]==0 && mark[t])dp[y]=-1;
cout<<dp[t]<<'\n';
}
else{
int d=0;
for(auto i:pre[t]){
if(!mark[i.fr]){
d=1;
cout<<i.sc<<'\n';
break;
}
}
if(!d)
cout<<-1<<'\n';
}
for(int i=0;i<y;i++)
mark[a[i]]=0;
}
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:20:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | while(pre[i].size()<sq && cnt<v[i].size()){
| ~~~^~~~~~~~~~~~
bitaro.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
bitaro.cpp:23:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(p[j]>=pre[x].size() )continue;
| ~~~~^~~~~~~~~~~~~~~
bitaro.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | while( p[j]<pre[x].size()&&mark[pre[x][p[j]].fr] )p[j]++;//cout<<j<<" "<<p[j]<<endl;
| ~~~~^~~~~~~~~~~~~~
bitaro.cpp:25:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(p[j]>=pre[x].size()){
| ~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |