Submission #218593

#TimeUsernameProblemLanguageResultExecution timeMemory
218593someone_aaBitaro’s Party (JOI18_bitaro)C++17
0 / 100
10 ms9728 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 100100; const int b = 1010; set<pair<int,int> > st[maxn]; vector<int>g[maxn], ig[maxn]; vector<int>order; bool visited[maxn]; int n, m, q; void dfs(int node) { if(visited[node]) return; visited[node] = true; for(int i:g[node]) { if(!visited[i]) { dfs(i); } } st[node].insert(mp(0, node)); order.pb(node); } void preprocess() { for(int i=1;i<=n;i++) { if(!visited[i]) dfs(i); } reverse(order.begin(), order.end()); for(int node:order) { for(int i:ig[node]) { //update st[node] with values from st[i] + 1 // Possible optimization point, in case of TLE for(auto vals:st[i]) { st[node].insert(mp(vals.first+1, vals.second)); if(st[node].size() > b) { st[node].erase(st[node].begin()); } } } } } bool blocked[maxn]; void solve() { int node, qs, x; vector<int>points; cin>>node>>qs; for(int i=0;i<qs;i++) { cin>>x; points.pb(x); blocked[x] = true; } if(qs > b) return; // DO DFS HERE int maxtunnels = 0; for(auto i:st[node]) { if(!blocked[i.second]) maxtunnels = max(maxtunnels, i.first); } cout<<maxtunnels<<"\n"; for(int i:points) blocked[i] = false; } int main() { cin>>n>>m>>q; int a, b; for(int i=0;i<m;i++) { cin>>a>>b; g[a].pb(b); ig[b].pb(a); } preprocess(); while(q--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...