#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 |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
2072 ms |
340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
2072 ms |
340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
2072 ms |
340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |