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;
vector <int> a[100001],topo;
int n,m,q,u,v,i,kq,sl,d[100001],f[100001],s;
void DFS(int u)
{
d[u]=1;
for(int i=0;i<a[u].size();i++)
{
int v=a[u][i];
if(d[v]==0) DFS(v);
}
topo.push_back(u);
}
int main()
{
//freopen("bitaro.inp","r",stdin);
//freopen("bitaro.out","w",stdout);
cin>>n>>m>>q;
while(m--)
{
cin>>u>>v;
a[u].push_back(v);
}
for(i=1;i<=n;i++)
if(d[i]==0) DFS(i);
while(q--)
{
cin>>s>>sl;
for(i=1;i<=n;i++) d[i]=0;
while(sl--) { cin>>u; d[u]=1; }
kq=-1;
for(i=0;i<topo.size();i++)
{
u=topo[i];
f[u]=-1;
if(u==s) f[u]=0;
for(int i=0;i<a[u].size();i++)
{
v=a[u][i];
if(f[v]>-1) f[u]=max(f[u],f[v]+1);
}
if(d[u]==0) kq=max(kq,f[u]);
}
cout<<kq<<'\n';
}
}
Compilation message (stderr)
bitaro.cpp: In function 'void DFS(int)':
bitaro.cpp:8:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a[u].size();i++)
~^~~~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<topo.size();i++)
~^~~~~~~~~~~~
bitaro.cpp:38:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a[u].size();i++)
~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |