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 ll long long
#define endl '\n'
#define pb push_back
using namespace std;
const ll mx=1007, INF=1e18L+5;
vector<ll>v[mx];
ll mxds=-1;
ll ds[mx];
ll p,nab;
void dfs(ll x)
{
if(x==p)mxds=max(mxds,ds[x]);
for(auto u:v[x])
{
ds[u]=ds[x]+1;
dfs(u);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,m,q;
cin>>n>>m>>q;
for(int i=0;i<m;i++)
{
ll x,y;
cin>>x>>y;
if(x>y)swap(x,y);
v[x].push_back(y);
}
while(q--)
{
cin>>p>>nab;
ll arr[n+1]={};
mxds=-1;
for(int i=0;i<nab;i++)
{
ll x;
cin>>x;
arr[x]=1;
}
for(int i=1;i<=n;i++)
{
if(arr[i]==0)
{
if(i==p)
{
mxds=max(mxds,0ll);
}
else
{
for(int j=1;j<=n;j++)ds[j]=0;
dfs(i);
}
}
}
cout<<mxds<<endl;
}
return 0;
}
/*
5 6 1
1 2
2 4
3 4
1 3
3 5
4 5
2 3 1 4 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |