Submission #567344

#TimeUsernameProblemLanguageResultExecution timeMemory
567344MajidBitaro’s Party (JOI18_bitaro)C++17
7 / 100
2057 ms63876 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...