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;
//Types
using ll = long long;
using db = double;
//Vectors
#define pb push_back
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(), vec.end()
//things
#define f first
#define s second
const int SMALLINF = 1e9 + 7;
const ll BIGINF = ((ll)1e18) + 7;
#define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
vector<ll> connect[20007];
// map<ll, map<ll, ll> > dist;
map<ll, ll> dist;
map<ll, bool> visited;
map<ll, map<ll, ll> > ans;
deque<ll> top;
void dfs(ll x){
visited[x] = true;
for(auto y: connect[x]){
if(!visited[y]){
dfs(y);
}
// path[x] = max(path[x], path[y]+1);
}
top.pb(x);
}
void solve(){
ll n, m, q;
cin>>n>>m>>q;
for(ll i = 0; i < m; i++){
ll u, v;
cin>>u>>v;
connect[u].pb(v);
// connect[v].pb(u);
}
for(ll i = 1; i <= n; i++){
if(!visited[i])dfs(i);
}
for(ll i = 1; i <= n; i++){
for(ll j = 1; j <= n; j++){
if(i!=j)dist[j] = BIGINF;
}
dist[i] = 0;
deque<ll> top2 = top;
while (!top2.empty()){
ll u = top2.back();
top2.pop_back();
// cout<<u<<" ";
if (dist[u]!=BIGINF){
for (auto v : connect[u]){
if (dist[v] > dist[u] - 1){
dist[v] = dist[u] - 1;
// cout<<"here: "<<dist[v]<<" "<<dist[u]<<"\n";
}
}
}
}
// cout<<i<<": ";
for(ll k = 1; k <= n; k++){
ans[i][k] = dist[k]*-1;
// if(dist[k]==BIGINF)cout<<"! ";
// else cout<<dist[k]*-1<<" ";
dist[k] = 0;
}
// cout<<"\n";
}
while(q--){
ll t, y;
cin>>t>>y;
map<ll, bool> no;
for(ll i = 0; i < y; i++){
ll x;
cin>>x;
no[x] = true;
}
ll mx = -1;
for(ll i = 1; i <= n; i++){
if(!no[i]){
mx = max(mx, ans[i][t]);
// cout<<i<<" "<<dist[i][t]<<"\n";
}
}
cout<<mx<<" ";
}
}
int main(){
Speeed
ll t=1;
// cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |