Submission #567159

#TimeUsernameProblemLanguageResultExecution timeMemory
567159DodoBitaro’s Party (JOI18_bitaro)C++14
0 / 100
2072 ms384 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...